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

Print records until new group and then skip 1

Status
Not open for further replies.

mrr

Technical User
May 3, 2001
67
US
I am trying to parse a space delimited input file that looks like:
001 1001 683784.0 9858088.0 4 1412
001 1001 683784.0 9858088.0 100 1412
001 1001 683784.0 9858088.0 200 1411
001 1001 683784.0 9858088.0 300 1411
001 1001 683784.0 9858088.0 400 1411
001 1002 683928.0 9858047.0 4 1409
001 1002 683928.0 9858047.0 100 1409
001 1002 683928.0 9858047.0 200 1409
001 1002 683928.0 9858047.0 300 1409
001 1002 683928.0 9858047.0 400 1409
001 1003 683928.0 9858047.0 4 1409
001 1003 683928.0 9858047.0 100 1409
001 1003 683928.0 9858047.0 200 1409
001 1003 683928.0 9858047.0 300 1409
001 1003 683928.0 9858047.0 400 1409
001 1004 683928.0 9858047.0 4 1409
001 1004 683928.0 9858047.0 100 1409
001 1004 683928.0 9858047.0 200 1409
001 1004 683928.0 9858047.0 300 1409
001 1004 683928.0 9858047.0 400 1409
001 1005 683928.0 9858047.0 4 1409
001 1005 683928.0 9858047.0 100 1409
001 1005 683928.0 9858047.0 200 1409
001 1005 683928.0 9858047.0 300 1409
001 1006 683928.0 9858047.0 4 1409
001 1006 683928.0 9858047.0 100 1409
001 1006 683928.0 9858047.0 200 1409
001 1006 683928.0 9858047.0 300 1409
001 1006 683928.0 9858047.0 400 1409
001 1006 683928.0 9858047.0 500 1409
001 1007 683928.0 9858047.0 4 1409
001 1007 683928.0 9858047.0 100 1409
001 1007 683928.0 9858047.0 200 1409
001 1007 683928.0 9858047.0 300 1409
001 1007 683928.0 9858047.0 400 1409
001 1007 683928.0 9858047.0 500 1409
002 1000 683928.0 9858047.0 4 1409
002 1000 683928.0 9858047.0 100 1409
002 1000 683928.0 9858047.0 200 1409
002 1000 683928.0 9858047.0 300 1409
002 1000 683928.0 9858047.0 400 1409
002 1000 683928.0 9858047.0 500 1409
002 1001 683928.0 9858047.0 4 1409
002 1001 683928.0 9858047.0 100 1409
002 1001 683928.0 9858047.0 200 1409
002 1001 683928.0 9858047.0 300 1409
002 1001 683928.0 9858047.0 400 1409
002 1001 683928.0 9858047.0 500 1409
002 1002 683928.0 9858047.0 4 1409
002 1002 683928.0 9858047.0 100 1409
002 1002 683928.0 9858047.0 200 1409
002 1002 683928.0 9858047.0 300 1409
002 1002 683928.0 9858047.0 9600 2400
002 1002 683928.0 9858047.0 9700 2401
002 1002 683928.0 9858047.0 10000 2478
002 1003 683928.0 9858047.0 4 1409
002 1003 683928.0 9858047.0 100 1409
002 1003 683928.0 9858047.0 200 1409
002 1003 683928.0 9858047.0 300 1409
002 1003 683928.0 9858047.0 400 1409
002 1003 683928.0 9858047.0 500 1409
...etc

Field 1 is a grouping number - not necessiarly incrementing by one.
Field 2 is a sub-number of field 1 with several sets of data following in the rest of the data record, also not necessiarly incrementing by one.
I want to parse the data so that I would have the output thinned by the combination of field 1 and 2.

I want to thin the ouput by printing every 3rd group of field 2 as related to field one.



Thus the ouput would be like:
001 1001 683784.0 9858088.0 4 1412
001 1001 683784.0 9858088.0 100 1412
001 1001 683784.0 9858088.0 200 1411
001 1001 683784.0 9858088.0 300 1411
001 1001 683784.0 9858088.0 400 1411
001 1004 683928.0 9858047.0 4 1409
001 1004 683928.0 9858047.0 100 1409
001 1004 683928.0 9858047.0 200 1409
001 1004 683928.0 9858047.0 300 1409
001 1004 683928.0 9858047.0 400 1409
001 1007 683928.0 9858047.0 4 1409
001 1007 683928.0 9858047.0 100 1409
001 1007 683928.0 9858047.0 200 1409
001 1007 683928.0 9858047.0 300 1409
001 1007 683928.0 9858047.0 400 1409
001 1007 683928.0 9858047.0 500 1409
002 1000 683928.0 9858047.0 4 1409
002 1000 683928.0 9858047.0 100 1409
002 1000 683928.0 9858047.0 200 1409
002 1000 683928.0 9858047.0 300 1409
002 1000 683928.0 9858047.0 400 1409
002 1000 683928.0 9858047.0 500 1409
002 1003 683928.0 9858047.0 4 1409
002 1003 683928.0 9858047.0 100 1409
002 1003 683928.0 9858047.0 200 1409
002 1003 683928.0 9858047.0 300 1409
002 1003 683928.0 9858047.0 400 1409
002 1003 683928.0 9858047.0 500 1409
etc...

Here's my starter script:
BEGIN { FS = " " }
NR == 1 {
prev_field1=$1
prev_field2=$2
}
$1 == prev_field1 && $2 == prev_field2
{
print $0
prev_field1=$1
prev_field2=$2
field_2_count++
}

$1 == prev_field1 && $2 != prev_field2
{
field_2_count++
next;
}

I'm stumped.
Thanks for any help.
 
Something like this ?
f1!=$1{c=1;f1=$1;f2=$2}
f2!=$2{++c;f2=$2}
c%3==1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, your script worked great and is very clean and efficient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top