awk command doubt
5 posters
awk command doubt
What is awk?
NF?
FS?
OFS?
$0?
-F?
' '?
NF?
FS?
OFS?
$0?
-F?
' '?
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: awk command doubt
NF - number of fields
FS - Field Separator
$0 - refers to the complete line , whereas $1 refers to field 1
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
Re: awk command doubt
how to use awk to locate lines longer than 100 and smaller than 150 characters.......?
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: awk command doubt
awk ' { if (length > 100 && length < 150) print }' filename
I have edited this now.Must be spacing problem.It is working for me!
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
Re: awk command doubt
[335723@oracleclient ~]$ awk '{length 5 && length < 10 ) print }' aaa.txt
awk: {length 5 && length < 10 ) print }
awk: ^ syntax error
help me out...........
awk: {length 5 && length < 10 ) print }
awk: ^ syntax error
help me out...........
anand- Posts : 55
Points : 70
Join date : 2010-02-26
Age : 36
Re: awk command doubt
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
Re: awk command doubt
What is the use of BEGIN pattern in awk cmd?
Can any1 explain with an example??
Can any1 explain with an example??
Saradha Kannan- Posts : 25
Points : 25
Join date : 2010-03-04
Re: awk command doubt
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
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...
Re: awk command doubt
Hey thanks..
understood
understood
Saradha Kannan- Posts : 25
Points : 25
Join date : 2010-03-04
Re: awk command doubt
Can someone post more examples of awk command usage with explanation?
jennyinhere- Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35
Re: awk command doubt
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.
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
Re: awk command doubt
What does awk -f sample.awk do ?
What is the purpose of -f ?
What is the purpose of -f ?
jennyinhere- Posts : 24
Points : 30
Join date : 2010-02-26
Age : 35
Re: awk command doubt
'-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.
Permissions in this forum:
You cannot reply to topics in this forum
|
|