field values getting changed in awk
This is quite confusing, so I am going to show all my steps in building to
to issue:
awk 'BEGIN { FS == /\s\s\s\s/ } ;
{
if ( NF == 0 )
next
else
{{ print "-------------NR = " NR "-----------------------NF = " NF }
for (i = 0; i <= NF; i++)
{{ print ( i, $i )} }
}
}' 200_Undercounter_Series.txt > new.txt
Produces the desired results (I have only included the records that are
relevant):
-------------NR = 9-----------------------NF = 7
0 1. 3510090 Shelf
Guard (See SN Breaks)
1 1.
2 3510090
3 Shelf
4 Guard
5 (See
6 SN
7 Breaks)
-------------NR = 10-----------------------NF = 6
0 3515980 Shelf Guard
(See SN Breaks)
1 3515980
2 Shelf
3 Guard
4 (See
5 SN
6 Breaks)
Notice the values for fields 1 and 2 of record 9, and field 1 for record
10. My desire is to separate these 2 records from the rest of the file, so
I zone in on the value of field 2 for record 9 as such:
if ( NF == 0 )
next
else
{{ print "-------------NR = " NR "-----------------------NF = " NF }
for (i = 0; i <= NF; i++)
{if ( $2 = /[0-9][0-9][0-9][0-9][0-9][0-9][0-9]/)
{ print ( ">>", i, $i)}
else
{ print ( i, $i )}
}
}
}' 200_Undercounter_Series.txt > new.txt
And I receive these results:
-------------NR = 9-----------------------NF = 7
>> 0 1. 1 Shelf Guard (See SN Breaks)
1 1.
2 0
3 Shelf
4 Guard
5 (See
6 SN
7 Breaks)
-------------NR = 10-----------------------NF = 6
>> 0 3515980 1 Guard (See SN Breaks)
>> 1 3515980
>> 2 1
>> 3 Guard
>> 4 (See
>> 5 SN
>> 6 Breaks)
Notice not only that the '>>' indicators are on the record NOT specified
($2 = /regex/), but field 2 in record 9 is now = 0!!!
There is no other code in my program at this point. What am I missing here?
Thanks
No comments:
Post a Comment