gawk awk awkiness

23 Jun

gawk can be used to add numbers together and average them:

gawk ‘{a=a+$1}END{print a/NR}’

I used this to get average load values:
sar -q | awk ‘{print $6}’ | grep -e “^[0-9].*” | gawk ‘{a=a+$1}END{print a/NR}’

Heres some more awkiness:
for i in `ls`; do cat $i | egrep -v “It was submit|—” | awk -F: ‘BEGIN{ORS=””} {print $2; print “,”; print $3; print “\n”}’ ; done
– The “for i in `ls`” is a bash loop
– The “-F:” specifies that a colon (“:”) will be the field sepeartor
– The “ORS=””” specifies that the Output Record Separtor will be nothing (usually it is a new line)
– The “done” is the end of the bash loop

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: