1753830 Members
8726 Online
108806 Solutions
New Discussion юеВ

Re: runawk

 
unixadmin_1
Frequent Advisor

runawk

I got example program written in awk how to compile and run this program..please let me know its urgent
10 REPLIES 10
Venkatesh BL
Honored Contributor

Re: runawk

# awk -f filename

Hemmetter
Esteemed Contributor

Re: runawk

Hi,

you run that program by calling:
$ awk -f program.file data.file

or you modify the first of programm file to:

#/usr/bin/awk

so that program is executed directly by awk.

rgds
HGH

unixadmin_1
Frequent Advisor

Re: runawk

with what extensions awk programms are saved and i do not understand wht is program .file and data.file in this: $ awk -f program.file data.file
Hemmetter
Esteemed Contributor

Re: runawk

hi

you are free in naming your awk script. Unix does not know something like file name extensions as windows does ( e.g. *.exe ).

i used "program.file" and "data.file" just as placeholder names. Replace them with the filenames you use.


rgds
HGH
Venkatesh BL
Honored Contributor

Re: runawk

If the file is named 'abc', use "awk -f abc" command to execute it.
unixadmin_1
Frequent Advisor

Re: runawk

i had saved with file name awk and how do i run this program and where do i run this
Peter Nikitka
Honored Contributor

Re: runawk

Hi,

it was not the best idea to name your program like the interpreter, 'test' would have been a name, I wouldn't recommend as well.
It may help you, using .awk as a suffix, if you are used to identify your home made programs that way.
NB: An awk program gets interpreted - there is no compiling stage.

1) Rename your awk-program named awk
mv awk prog1.awk
2) Check the first line of your program
sed 1q prog1.awk
3) If the output is not like this
#!/usr/bin/awk -f -
add a line with exactly this text.
4) Add the execute-bit to that program
chmod +x prog1.awk

Every awk program read the stdin, when no filename(s) are provided as parameters.
5) So just calling
./prog1.awk
will wait for data entered
6) ./prog1.awk "file-with-data"
will read that file
7) ... | ./prog1.awk
will read data from the pipe (output of the command "...")

mfG Peter


Now it depends, how your awk program works.
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Venkatesh BL
Honored Contributor

Re: runawk

"I have assigned points to 0 of 68 responses to my questions. " in your profile does not sound encouraging! :)

Please refer to http://forums11.itrc.hp.com/service/forums/helptips.do?#28 to understand about the member point system.
Peter Nikitka
Honored Contributor

Re: runawk

Hi,

I just so the connection to another thread of you:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1302055

Your question and answers direct me to this awk program, which you should save as
file /usr/local/checkid.awk

#!/usr/bin/awk -f -
BEGIN {FS=":"}
{
# print $1, $3, $5
if ($1 == "+") next
if ($5 == "") {
print "No user name for", $1
}
if ($3 == 0) {
print "superuser", $1, $5
if ($1 != "root") {
print "superuser but not root:", $1, $5, "<******"
}
}

Having done then the steps 1-4 of my previous post, execute this commandline under any directory:
/usr/local/checkid.awk /etc/passwd

Additions:
1) There may other naming services (NIS,...) active, but this could be out of the scope you can handle by yourself.
ypcat passwd | /usr/local/checkid.awk

would examine NIS for example.

2) Can it be, that your clients notice was a direction to UIDs used on this system, not having an entry in a passwd database (/etc/passwd; NIS) at all?
For example, a command like
ls -ld "file-uid-only"
would not show a name in the user column but only a number for a file owned by such an UID.

Good luck!
Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"