JimR
JimR

Reputation: 513

Field separators

I have a lot of programming experience, but I am fairly new to awk. Something is not behaving as I expect. Can somebody put me straight?

On linux, my command: gawk -f do3 tmp6.txt

My source file do3

#!/bin/gawk -f
BEGIN {
FS="-"
}
{print "Two is " $2 "One is" $1 "zero is" $0}

My input file, tmp6.txt

~BAND:3-10M
~MODE:2-CW
~QSO_DATE:8-20111130
~TIME_ON:6-175415
~eor-

~PFX:2-K4
~CQZ:1-5
~ITUZ:1-8
~eor-

My output to the console:

One is~BAND:3zero is~BAND:3-10M
One is~MODE:2zero is~MODE:2-CW
One is~QSO_DATE:8zero is~QSO_DATE:8-20111130
One is~TIME_ON:6zero is~TIME_ON:6-175415
One is~eorzero is~eor-
zero isOne is
One is~PFX:2zero is~PFX:2-K4  
One is~CQZ:1zero is~CQZ:1-5
One is~ITUZ:1zero is~ITUZ:1-8
One is~eorzero is~eor-
zero isOne is

Taking the first line as the example, what I could have expected was in every line, what I think should be the beginning would be

Two is followed by the value assigned to $2, the value after the "-" in each line.

However, that is missing in every case.

Other cases that are more complex exhibit even more unusual behavior (like back-tabbing), but if I can figure this part out, maybe that will help me understand the rest.

Thanks in advance, JimR

Upvotes: 1

Views: 86

Answers (1)

Guru
Guru

Reputation: 16974

Most likely your file seems to contain ^M at the end of the line. Before running the gawk command:

dos2unix tmp6.txt

which will remove the ^M characters.

Upvotes: 3

Related Questions