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!

I need help on : how to compare two

Status
Not open for further replies.

bholav

Technical User
Jun 13, 2002
15
US
I need help on : how to compare two different fields on two differnt lines ,for example in the file below,

. . . . . . . . . . . . 1 . 1 1 1 . . . . . . . . . . . .
. . . . . . . . . . . 1 1 . 1 1 . 1 . . . . . . . . . . .
. . . . . . . . 1 1 . 1 1 . 1 1 . 1 1 1 . . . . . . . . .
2 7 9 9 2 3 2 2 2
2 9 9 9 1 1 1 1 2
1 1 9 2 1 1 1 1 1 1 3 2

I need to compare field 13 on line 1 (which is "1" with field 1 of line 4 (which is a "2" and drop the result back in field 13 of line 1.

I find this forum very informative.Thanks
 
Assuming that all the fields are one character long and you only need to do the replacement once in the file, this script will do what you want. Otherwise you could use split() to isolate field 13 for replacement.
Code:
{
  a[NR] = $0
}
END { a[1] = substr(a[1],1,24) substr(a[4],1,1) substr(a[1],26)
      for (i=1;i<=4;i++) print a[i]
}
Hope this helps. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top