|
|
|
awk question
|
Original Message
|
Name: narsman
Date: August 30, 2005 at 16:21:11 Pacific
Subject: awk questionOS: Windows 2000NTCPU/Ram: 512 |
Comment: 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.223556 I 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.
Report Offensive Message For Removal
|
|
Response Number 2
|
Name: narsman
Date: August 30, 2005 at 16:42:16 Pacific
|
Reply: (edit)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.757888 Please note that the value of the 2nd and 3rd fields are switched. Thanks again.
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: nails
Date: August 31, 2005 at 14:02:47 Pacific
|
Reply: (edit)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.
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|