I have this file:
names average
john:15.02
Mark:09.63
James:12.58
I want to extract only the averages greater than 10 from it, so the output in this example should be:
15.02
12.58
awk
awk -F: '{if($2>10)print$2}' <filename
-F:
– sets the F
ield separator to :
{if($2>10)print$2}
– for each line, test whether the 2
nd field is >10
, if so print
it<filename
– let the shell open file filename
, that's better than letting awk
do that, see Stéphane Chazelas' answer on the topic$ <filename awk -F: '{if($2>10)print$2}'
15.02
12.58
It's also possible to add spaces and put the pattern outside the brackets, so these are equal – thanks to Stefan for pointing that out:
awk -F: '{if($2>10)print$2}' <filename
awk -F: '{ if ( $2 > 10 ) print $2 }' <filename
awk -F: '$2>10{print$2}' <filename
awk -F: '$2 > 10 { print $2 }' <filename
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments