Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need help with awk:
abc 76.33009, 99.88804
abc 76.45004, 98.98344
abc 22.33733, 90.223456
abd 98.7490, 98.870003
abd 12.331113, 98.444501
abe 98.757888, 21.223556I need the output to group field 1 by it's matching pattern. In other words, I want all abc's together, abd's together, abe's together. The last requirement is to multiply the numbers by 1000 and do not truncate the decimal numbers.
Thanks for your help.

Hi nails,
Sorry if my question is not clear. I want my output to be:
GROUP ABC,
LOC 99888.04/76330.09
LOC 98983.44/76450.04
LOC 90223.456/22337.33
*
GROUP ABD,
LOC 98870.003/98749.0
LOC 98444.501/12331.113
*
GROUP ABE,
LOC 21.223556/98.757888Please note that the value of the 2nd and 3rd fields are switched.
Thanks again.

No, the only way I can see to do it in awk with an unsorted file is saving the data in a 2-dimensional array and printing it out at the end.
Makefile sure your file is sorted by field one before you start:
sort -k 1,1 myfile|
nawk ' BEGIN { myvar="aa"; fr=1}
{
gsub(",", "",$2) # get rid of the comma
if ($1 != myvar)
{
myvar=$1
if(fr != 1)
print "*"
printf("GROUP %s,\n", $1)
fr=0
}
printf("LOC %8.4f/%8.4f\n", ($3 * 1000), ($2 * 1000))
} 'Since I'm using Solaris, I'm using nawk; change it to awk for non-Solaris.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |