1

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

4

1 回答 1

3

您的文件很可能在行尾包含 ^M。在运行gawk命令之前:

dos2unix tmp6.txt

这将删除 ^M 字符。

于 2013-01-22T08:09:56.103 回答