[英]Adding suffix not working with sed and awk on macOS
These are the contents of t.txt
这些是t.txt
的内容
ABCDEFG
ABCDEFG
ABCDEFG
ABCDEFG
I tried these commands to add a suffix to the end of the line: 我尝试使用以下命令在行尾添加一个后缀:
$ cat t.txt | sed -e 's/$/-asdf/'
$ cat t.txt | awk '{ print $0 "-asdf" }'
The result in macOS: 在macOS中的结果:
-asdfFG
-asdfFG
-asdfFG
ABCDEFG-asdf
The result in Linux: 在Linux中的结果:
ABCDEFG-abcd
ABCDEFG-abcd
ABCDEFG-abcd
ABCDEFG-abcd
Why do I not get the same result in macOS? 为什么在macOS中无法得到相同的结果?
You have carriage returns in your file. 您的文件中有回车符。 macOS Sierra, using built-in sed on an LF-only file: 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
Re-saved it with CRLF: 用CRLF重新保存:
mike ~ ❱❱❱ /usr/bin/sed -e 's/$/-asdf/' t.txt
-asdfFG
-asdfFG
-asdfFG
-asdfFG
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.