Visit Our UNIX and Linux User Community


How to excute an awk file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to excute an awk file
# 1  
Old 08-05-2009
Question How to excute an awk file

Hi All,
Greetings.
I am working with an awk file say "Test.awk".
My Input file is say "test"

I am executing the awk file using
Code:
awk -f Test.awk test

I am new to awk. I wanted to know how can we execute the above awk command from a ksh file. Please help me on this.

Thanks in advance!!
# 2  
Old 08-05-2009
Either like you wrote it already or use something like
Code:
#!/usr/bin/ksh

...
<maybe some more shell code>
...
awk -f Test.awk test
...
<maybe some more shell code>
...

exit 0

Why don't you just test it or did I misunderstand?
# 3  
Old 08-05-2009
If you have done interactive commandline on the terminal and it works, you can write it also to the shell script. And vice versa. Interactive shell = read shell script from terminal = stdin. Shell script = read commandlines from file, not from stdin.
# 4  
Old 08-05-2009
Thanks all..
I am having one more doubt..
Can I execute the awk file in a loop from ksh file.
For example

Code:
#!/bin/ksh
while read file
do
echo $file
echo "Total Number of Records in " $file ":"`wc -l $file |awk '{print $1}'`
awk -f Test.awk $file
done < filelist

where as filelist contains the list of input files..
I have tried this by giving list of 3 files in the filelist..But,It is not working. Please help
It is executing only the first file in the list
# 5  
Old 08-05-2009
show the content of filelist... are you putting them in a single line??
# 6  
Old 08-05-2009
Question

Hi Rakesh..
I have rectified that. It was due to the space issue in the filelist file.

One more thing,
Can we able to get the name of the input file name in the awk file?
What I mean ,
Code:
awk -f test.awk inputfile

we are executing the above command from ksh..By any chance can we get the value of the input file inside the awk file?
Hope my question is clear Smilie
# 7  
Old 08-05-2009
Code:
#!/bin/ksh
while read file
do
   # echo result ok ?
   echo "$file"
   lines=$( wc -l < "$file" )
   echo "Total Number of Records in $file: $lines"
   # set variable filename and use it in your Test.awk or use builtin variable FILENAME
   awk -v filename="$file" -f Test.awk "$file"
done < filelist

GNU Awk-doc

Output without awk line. If you have still problem, give cut&paste filelist and output.

Previous Thread | Next Thread
Test Your Knowledge in Computers #914
Difficulty: Medium
In bash, grep -v -e '^[[:space:]]*$' file.txt will filter all the blank lines from file.txt and save the results in a file called file.txt.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Login, excute command, logout Script Help

Good Evening all, After spending the last week or so reading many posts I decided to register and join in. This is my first post on the forum so please forgive me as im new to this, Im after some help in throwing together a quick basic script without using expect to change the password on several... (4 Replies)
Discussion started by: mutley2202
4 Replies

2. SuSE

cant excute /etc/init/rc*

hi Guys, i'm new to linux i have some problem after reboot it showing like this error .. end -request: i/o error / dev hdb, sector 2566830 cant excute : /etc/init.d/rc No more process /etc in this run level any one know .. plz reply soon ... coz i 'm working as data center (2 Replies)
Discussion started by: coolboys
2 Replies

3. OS X (Apple)

cannot excute binary file

Hi, I am a new user of Mac OSX 10.7 (Lion). I am trying to compile a program and followed steps as: 1: qmake program_name.pro Not to mention I have installed qt and program compile perfectly without error and create a Makefile. 2: make Again everything worked fine and I got an executable... (1 Reply)
Discussion started by: karun25u
1 Replies

4. UNIX Desktop Questions & Answers

ssh command doesnot excute commands in the destination server

Hi All, I have the below code where Iam connecting from xzur111pap server to xzur0211pap server thru ssh to execute some commands. ssh xzur0211pap spaceleft=`df -k /home |tail -1 | awk '{print $5}'` spaceleft=${spaceleft%\%} if ]; then echo "ALERT : HUFS(/home $spaceleft)" exit 0... (3 Replies)
Discussion started by: gaddamja
3 Replies

5. Shell Programming and Scripting

logging into server and excute commands

hi all, I am new to unix and unix scipting. i need a script to logging into servers and to excute some commands in each server. for eg : I tried with below script ,but cant get the desired o/p. please help with this for i in `cat serverlist` do echo $i ssh $i uname -a ; cat... (4 Replies)
Discussion started by: sudharson
4 Replies

6. Cybersecurity

prevent user from excute command

Dears I want to prevent users from doing spesific command "history -c" or "history" in general How can I do ? (4 Replies)
Discussion started by: reaky
4 Replies

7. Shell Programming and Scripting

Excute file then..

I have a text file with only the command: MyTextFile: ls -l in it.. So in my sript im trying.. sh MyTextFile.txt >> MyTextFile.txt Just to overwrite and replace the command with its output. sh MyTextFile.txt 2>1 MyTextFile.txt isnt redirecting either.. :( Im getting the... (3 Replies)
Discussion started by: omgsomuchppl
3 Replies

8. UNIX for Dummies Questions & Answers

Executing file without excute permission.

Hi, I have a file which don't have execute permission, but still it can be executed by "sh" like as below. ------------------------------------------------------------------ -rw-r----- 1 root other 30 May 8 15:43 test.sh (svpkg1-nd:root) - ./test.sh ./test.sh: cannot execute... (4 Replies)
Discussion started by: ashish_uiit
4 Replies

9. Shell Programming and Scripting

is there any way to excute script every N seconds?

Hello i have script that show me stuff , i need to excute this script every N seconds , is there any way to do it with one liner ? ( mybe perl ) thanks (7 Replies)
Discussion started by: umen
7 Replies

10. UNIX for Advanced & Expert Users

help! can't excute

I can't excute any commands in /usr/bin when I try to excute commands in /usr/bin the error message is displayed " No Such device or address" Can you Help? Thanks in Advance (6 Replies)
Discussion started by: hassan2
6 Replies

Featured Tech Videos