I have a set of values in a column that go
3
4
4
5
6
7
8
...
I wish to decrement all these values by 1
Any ideas as开发者_开发问答 to how to formulate this in an AWK script?
thanks
What if I wish to increment the entries instead of decrementing?
Would awk '{ $7--; print $1 }' work?
If it's just a single column, this will do:
awk '{ $7--; print $0 }'
Instead of the '7' in '$7' you need to insert your column number; if this number is greater 10, write it as $(77), e.g.
If all columns of a row are affected, use this:
awk '{ for (f=1; f<=NF; f--) $f--
print $0
}'
Hope this helps,
Klaus
If they're in column 4, $4--
, and then do whatever else you were going to do (e.g. print).
精彩评论