Hi I am using a awk command but not getting required o/p.
input file
a.txt
2 ak
3 cb
4 de
5 gh
6 ij
awk program
BEGIN { x=0 }
{if ($1>3) {x=x+1}{print $0} }
END { print "I found " x " line have value more than 3" }
output
2 ak
3 cb
4 de
5 gh
6 ij
I found 3 line have value more than 3
required o/p
4 de
5 gh
6 ij
I found 3 line have value more than 3
How can i use two operation in single if statement like here i want to print the line and also increment counter.
{if ($1>3) {x=x+1;print $0} }
Thanks for reply.
Currently I am writing a awk program and running that by using
nawk -F" " -f b.awk file
Can I give complete command in a single line
like
nawk -F" " BEGIN '{ x=0 } {if ($1>3) {x=x+1;print $0} }' END '{ print "I found " x " line have value more than 3" }' file
but in this case it is giving error
nawk '$1>3 {x=x+1;print $0}END{ print "I found " x " line have value more than 3" }' file