1

lets say I have a basic text file that looks like this:

91 N 91 H 1.48
95 N 95 H -0.26
97 N 97 H 1.79
98 N 98 H -0.76

I want to change columns 1 and 3 so that the integer values are n-3 like this:

88 N 88 H 1.48
92 N 92 H -0.26
94 N 94 H 1.79
95 N 95 H -0.76

I realize awk is probably the best way to do this, but i have no idea how to get awk to apply a formula to a column, or for that matter for awk to treat a column as integer values. Is there a simple script that could do this? Also on that note: what a good comprehensive guide to how to use awk, because the ones I've seen so far are just example scripts of how to do things.

3

This substracts 3 from columns 1 and 3:

$ awk '{$1-=3; $3-=3; print;}' file
88 N 88 H 1.48
92 N 92 H -0.26
94 N 94 H 1.79
95 N 95 H -0.76

-= is the usual subtract-from operator. It works the same in awk as it does in C or python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.