![](/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.