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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

record field extraction

Status
Not open for further replies.

christiniaroelin

Programmer
Sep 15, 2004
26
US
Hi,

i need to pull out field values( low and high) according to the following logic:

pullout the value from record 1, column 3 => low 1
jump down 12 records; pull out the value from column 4 =>high1
pull out the value from the next record( the very next subsequent record, i.e. record 13) => low2
jump down 12 records( i.e. record 25); pull out the value from column 4 =>high2
pull out the value from the next record( the very next subsequent record, i.e. record 26) => low3
jump down 12 records( i.e. record 38); pull out the value from column 4 =>high3
.....and so on for 6 low and high pairs.

The value from column 3 will give the low# value and the
value from column4 jumped down to 12 records from the corresponding low record will give the
high value.
Please, advice me on how to go about this.
Thanks in advance for your time and help

regards,
christinia
 
Not the neatest way but it works :

Stick the below into a file , say file1

Make it executable

Use ./file1 datafile (where datafile is your own data)

Hope this helps,

Martin



#!/usr/bin/awk -f

BEGIN {RN=1}


{
if (NR==RN+0) print $3
if (NR==RN+12) print $4
if (NR==RN+13) print $3
if (NR==RN+25) print $4
if (NR==RN+26) print $3
if (NR==RN+38) print $4
if (NR==RN+39) print $3
if (NR==RN+51) print $4
if (NR==RN+52) print $3
if (NR==RN+64) print $4
if (NR==RN+65) print $3
if (NR==RN+77) print $4
}
 
Bit neater, same as before cope into a file, say file1 ...

#!/usr/bin/awk -f

BEGIN {COUNTER=1}
{

if (NR==1){
print $3
COUNTER=COUNTER+12
}
else

if (COUNTER==78 && NR==COUNTER){
print $4
exit
}


if (NR==COUNTER){
print $4
getline
print $3
COUNTER=COUNTER+13
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top