1) Simple Awk commands:
Examples:
# date
Mon Nov 30 09:46:09 IST 2009
# date | awk '{print $2}'
Nov
# date | awk '{print $2 " " $6}'
Nov 2009
# date | awk '{print "Month : " $2 " Year : " $6}'
Month : Nov Year : 2009
2) Awk command with a use of variable:
#Command | awk -v h="$hostname" '{print $0, h}'
Here h is a variable called hostname .
If a ouput of command is
Aaa 111 222
Bbb 333 444
Ccc 444 444
And when you pipe it to awk .
For example.
#Command | awk -v h="$hostname" '{print $0, h}'
The output will be:
Aaa 111 222 hostname
Bbb 333 444 hostname
Ccc 444 444 hostname
Advanced AWK
#xm list" < /dev/null | grep -v Name |awk 'BEGIN {tot=0} "totalvcpu" {tot=tot+$4} END {print tot}'
The above command will sum up 4 column returned by xm list" < /dev/null | grep -v Name and display to total of every value in column 4.
More will be coming soon.
Please Leave us with your comments and Queries/Suggestions.
I will try to reply asap.
No comments:
Post a Comment