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!

Reverse order of points 1

Status
Not open for further replies.

mrr

Technical User
May 3, 2001
67
US
Can someone help me with a syntax error on this small gawk script?
My input is like:
"ITEM1","",-6
-79.471207878102078,40.185904961536473
-79.471110437609283,40.186013888181662
-79.471012969863153,40.186122801305608
-79.470915474880968,40.186231700890886
-79.470817952283511,40.18634058672292
-79.470720401289327,40.186449458386832
"ITEM2","",-5
-79.480588912690266,40.137327883976646
-79.480520795075009,40.137752518467074
-79.480078078737492,40.140727925559467
-79.431175980661493,40.212378260510036
-79.430817901029741,40.212711867264595
"ITEM3","",-4
-79.499865919237621,40.096682432318033
-79.499623533047696,40.097444696601713
-79.499371738211565,40.098205286381464
-79.499112753934597,40.098964553407647

and I want to print the "ITEM..." record and then print the group of following points in reverse order"

Here's my script:
{
if (match($0, "^\"")) { print;next
{ line[NR] = $0 }
END { for (i=NR;i>0;i--)
print line }
}

Thanks for any suggestions!
 
the syntax error:
if (match($0, "^\"")) { print;next }
}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV!
It did remove the syntax error but the format for the output should be like:
"ITEM1","",-6
-79.470720401289327,40.186449458386832
-79.470817952283511,40.18634058672292
-79.470915474880968,40.186231700890886
-79.471012969863153,40.186122801305608
-79.471110437609283,40.186013888181662
-79.471207878102078,40.185904961536473
"ITEM2","",-5
-79.430817901029741,40.212711867264595
-79.431175980661493,40.212378260510036
-79.480078078737492,40.140727925559467
-79.480520795075009,40.137752518467074
-79.480588912690266,40.137327883976646
"ITEM3","",-4
-79.499112753934597,40.098964553407647
-79.499371738211565,40.098205286381464
-79.499623533047696,40.097444696601713
-79.499865919237621,40.096682432318033

Do you have a suggest to reverse the values within each group?

Thanks

 
Try this:

Code:
function printitem( j) {
        print line[itemline]
        for (j=i-1;j>itemline;j--) print line[j]
}
{ line[NR] = $0 }
END {
        itemline=1
        for (i=2;i<=NR;i++) {
                if (match(line[i], "^\"")) {
                        printitem()
                        itemline=i
                }
        }
        printitem()
}

Annihilannic.
 
Yes, this works perfectly.
Thanks PHV and Annihilannic!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top