Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to subtract only the lines with 2 numerical columns 2

Status
Not open for further replies.

whatisthis987

IS-IT--Management
Apr 24, 2007
34
US
Hi,
I have a file that looks like this:

line1 - This is line #1
line1 - This is line #1
11 11 11
500 600
600 700
700 800
line7 - This is line #7
line8 - This is line #8

I would like to subtract 10 ONLY from the lines with 2 numerical columns. Meaning it should look like this:

line1 - This is line #1
line1 - This is line #1
11 11 11
450 500
500 600
600 700
line7 - This is line #7
line8 - This is line #8

Can anyone help?
 
Hi

whatisthis987 said:
I would like to subtract 10
Sure you want 10 ? Your example is closer to 100.
whatisthis987 said:
Sure you want 450 ? According to you, should be 490, according to me, should be 400.

Assuming all 2 column lines are numeric :
Code:
awk 'NF==2{$1-=100;$2-=100}1' /input/file
Also checking for numeric values :
Code:
awk '/^[[:digit:]]+[[:space:]]+[[:digit:]]+$/{$1-=100;$2-=100}1' /input/file
Code:
awk '/^[0-9]+ +[0-9]+$/{$1-=100;$2-=100}1' /input/file

Feherke.
 
Thank you so much. That's exactly what I wanted. Really appreaciate your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top