在AWK字符串连接 [英] String concatenation in awk
本文介绍了在AWK字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑下面的文本文件(test.txt的):
Consider the following text file (test.txt) :
1 1 1
7 7 6
和awk脚本(test.awk)
and the awk script (test.awk)
{
print "$0 : ", $0
lines=(lines $0)
print "lines : ", lines
}
然后运行:
awk -f test.awk test.txt
给输出
$0 : 1 1 1
lines : 1 1 1
$0 : 7 7 6
7 7 6 : 1 1 1
而预期的输出应(据我可以看到)已
while the expected output should (as far as I can see) have been:
$0 : 1 1 1
lines : 1 1 1
$0 : 7 7 6
lines : 1 1 17 7 6
我是什么在这里失踪?
what am I missing here?
(我使用了GNU AWK 3.1.8在Ubuntu 12.04)
(I am using GNU Awk 3.1.8 on Ubuntu 12.04)
推荐答案
您已经有了DOS行结束在的test.txt
(CRLF或 \\ r \\ n
在每行的末尾)。
You've got DOS line endings in test.txt
(CRLF, or \r\n
at the end of each line).
Unix行结尾的输出:
Output with Unix line endings:
$0 : 1 1 1
lines : 1 1 1
$0 : 7 7 6
lines : 1 1 17 7 6
与DOS行结束输出:
Output with DOS line endings:
$0 : 1 1 1
lines : 1 1 1
$0 : 7 7 6
7 7 6 : 1 1 1
用十六进制转储程序格式化的DOS行结束输出:
Output with DOS line endings formatted with a hex-dump program:
0x0000: 24 30 20 3A 20 20 31 20 31 20 31 0D 0A 6C 69 6E $0 : 1 1 1..lin
0x0010: 65 73 20 3A 20 20 31 20 31 20 31 0D 0A 24 30 20 es : 1 1 1..$0
0x0020: 3A 20 20 37 20 37 20 36 0D 0A 6C 69 6E 65 73 20 : 7 7 6..lines
0x0030: 3A 20 20 31 20 31 20 31 0D 37 20 37 20 36 0D 0A : 1 1 1.7 7 6..
0x0040:
的 0D
codeS是CR行结尾。
The 0D
codes are the CR line endings.
这篇关于在AWK字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文