Hi,
I just don't understand awk. I think I'm close here but can someone give me a hand to finish this little parsing routine ?
the input file is formatted like this:
District 2502110
Gsub 2384889
Gsub 1428180
District 2502220
Gsub 1466390
Gsub 1466389
Gsub 1466388
Gsub 1466386
Gsub 1466385
District 2502710
The script should make a command for each Gsub line that contains it's district.
Here's what I got but doesn't work.
Thanks !
floyd
awk '
{
if (( $1 == "District" ))
{
dist=$2
while (( $1 != "District" ))
{
sub=$2
printf("dvmrgdel %s %s\n",sub,dist)
getline
}
}
}' file
Post desired output from that input file. Also use code tags.
the desired output is:
dvmrgdel 2384889 2502110
dvmrgdel 1428180 2502110
dvmrgdel 1466390 2502220
dvmrgdel 1466389 2502220
So the Gsubs within a district print with their respective districts.
One thing I found out so far is my use of the variable "sub" won't work because sub is a command in awk. So I changed it to subm.
Code again:
nawk '
{
if ( $1 == "District" )
{
dist=$2
while ( $1 != "District" )
{
subm=$2
printf("dvmrgdel %s %s\n",subm,dist)
getline
}
}
}' list
Try this:
awk '/District/{d=$2; next} {print "dvmrgdel " $2 FS d}' file
That is an awesome piece of effecient code and works !!
Thank you very much !