i have output of command given here.
id speed ncpu pmem vmem ep nproc io iops p1 100 1 1024m 1024m 20 100 1024 1024 a2 100 1 1024m 1024m 20 100 1024 1024 b2 b3 100 1 1024m 1024m 20 100 1024 1024 c3 c4 c5 100 1 1024m 1024m 20 100 0 1024
i need filter out values come under column 'id'
the command awk '{print $1}
prints only:
p1 a2 b2 c3
which not desired output.
the output i'm looking is.
p1 a2 b2 b3 c3 c4 c5
one way @ 'remove last 8 columns data':
awk '{ $(nf-8+1) = ""; nf -= 8; print }'
output:
id p1 a2 b2 b3 c3 c4 c5
if don't assign $(nf-8+1)
, awk
doesn't think $0
might have changed prints line unchanged. , use of $(nf-8+1)
allow use variable specify how many trailing columns omit:
awk -v omit="${howmany:-8}" '{ $(nf-omit+1) = ""; nf -= omit; print }'
if set shell variable howmany=6
, see 'speed' , 'ncpu' columns too:
id speed ncpu p1 100 1 a2 100 1 b2 b3 100 1 c3 c4 c5 100 1
tested both bsd , gnu variants of awk
.
Comments
Post a Comment