![](/img/trans.png)
[英]Parse output of mdimport using grep/awk/sed/etc. on macOS?
[英]Adding suffix not working with sed and awk on macOS
这些是t.txt
的内容
ABCDEFG
ABCDEFG
ABCDEFG
ABCDEFG
我尝试使用以下命令在行尾添加一个后缀:
$ cat t.txt | sed -e 's/$/-asdf/'
$ cat t.txt | awk '{ print $0 "-asdf" }'
在macOS中的结果:
-asdfFG
-asdfFG
-asdfFG
ABCDEFG-asdf
在Linux中的结果:
ABCDEFG-abcd
ABCDEFG-abcd
ABCDEFG-abcd
ABCDEFG-abcd
为什么在macOS中无法得到相同的结果?
您的文件中有回车符。 macOS Sierra,在仅LF文件上使用内置sed:
mike ~ ❱❱❱ cat t.txt
ABCDEFG
ABCDEFG
ABCDEFG
ABCDEFG
mike ~ ❱❱❱ /usr/bin/sed -e 's/$/-asdf/' t.txt
ABCDEFG-asdf
ABCDEFG-asdf
ABCDEFG-asdf
ABCDEFG-asdf
用CRLF重新保存:
mike ~ ❱❱❱ /usr/bin/sed -e 's/$/-asdf/' t.txt
-asdfFG
-asdfFG
-asdfFG
-asdfFG
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.