Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

awk command doubt

5 posters

Go down

awk command doubt Empty awk command doubt

Post by anand Thu Mar 04, 2010 6:40 pm

What is awk?
NF?
FS?
OFS?
$0?
-F?
' '?
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Maithreyi Thu Mar 04, 2010 6:43 pm

NF - number of fields
FS - Field Separator
$0 - refers to the complete line , whereas $1 refers to field 1

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by anand Thu Mar 04, 2010 6:48 pm

how to use awk to locate lines longer than 100 and smaller than 150 characters.......?
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Maithreyi Thu Mar 04, 2010 7:01 pm

awk ' { if (length > 100 && length < 150) print }' filename

I have edited this now.Must be spacing problem.It is working for me!


Last edited by Maithreyi on Thu Mar 04, 2010 7:09 pm; edited 1 time in total (Reason for editing : Spacing error)

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by anand Thu Mar 04, 2010 7:08 pm

[335723@oracleclient ~]$ awk '{length 5 && length < 10 ) print }' aaa.txt
awk: {length 5 && length < 10 ) print }
awk: ^ syntax error

help me out...........
anand
anand

Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Maithreyi Thu Mar 04, 2010 7:11 pm

Where is the if clause ? And inside if the condition is enclosed in ()

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Saradha Kannan Tue Mar 16, 2010 1:31 pm

What is the use of BEGIN pattern in awk cmd?
Can any1 explain with an example??

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Christopher Tue Mar 16, 2010 1:49 pm

BEGIN block ll be executed once the execution of awk file starts.
END block ll be executed once the exection ends.
Other blocks ll be executed for all ur inputs.

Example

Code:
$ cat sample.awk
BEGIN { print "WELCOME TO UNIX" }
{ print $1 }
END { print "THANK U.. VISIT AGAIN... " }

$ awk -f sample.awk
WELCOME TO UNIX
orange colour
orange
candle light
candle
THANK U.. VISIT AGAIN...
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Saradha Kannan Tue Mar 16, 2010 2:20 pm

Hey thanks.. Smile
understood

Saradha Kannan

Posts : 25
Points : 25
Join date : 2010-03-04

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by jennyinhere Wed Mar 24, 2010 12:41 pm

Can someone post more examples of awk command usage with explanation?

jennyinhere

Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Maithreyi Wed Mar 24, 2010 1:23 pm

awk basically reads one line at a time, matches the particular pattern specified.If the match is found, it performs the action on that line!

Eg :- awk '/gold/ {print}' coins.txt

If gold is found in any line of the file 'coins.txt' , then print all lines in coins.txt containing gold.

Maithreyi

Posts : 76
Points : 142
Join date : 2010-03-03
Age : 36
Location : Haldia

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by jennyinhere Wed Mar 24, 2010 2:28 pm

What does awk -f sample.awk do ?

What is the purpose of -f ?

jennyinhere

Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Christopher Thu Mar 25, 2010 11:23 am

'-f' means awk program is saved in a separate file and argument followed by -f is the name of the awk script file. multiple -f can also be used.
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

awk command doubt Empty Re: awk command doubt

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum