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!

getting vars from 2 different lines in a file 1

Status
Not open for further replies.

dendenners

Programmer
Jul 17, 2001
110
IE
Hi there,
I'm pretty new to awk and thus my knowledge is fairly patchy. I have a file with a header record (flagged as a header record by the fact that it begins with a "00") and a trailer record (begins with an "80") and I want to extract the substring from the 15th to the 30th character of the header record to one shell variable, and a similar substring from the trailer record to a different variable. Thanks in advance for any help
 
It's not clear as to whether you need to use awk for this. It can be done in the shell quite simply using

VAR1=`grep ^00 filename|cut -c15-30`
VAR2=`grep ^80 filename|cut -c15-30`

If you then need to use those variables in a script be sure to export them.

Greg.
 
Could anyone help on "how to compare two fields from two different lines.
For example in the file below,
compare field 13(which is a "1") on line 1 with filed 1 of line 4 (which is "2") and replace field 13 with the outcome of comparison.

. . . . . . . . . . . . 1 . 1 1 . 1 1 . . . . . . . . . . . . 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
8 2 1 9 9 1 1 1 1 1 9 9 9 1 1 9 1 1 1 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top