我正在尝试将其用作使用sed在OSX中向文件添加行的入门指南。https://stackoverflow.com/questions/25631989/sed-insert-line-command-osx
sed -i '.json' '2i\
this is a test place
' dummy.txt
以上作品。但是我需要进行扩展,所以我从简单的事情开始,只需替换为双引号
sed -i '.json' "2i\
this is a test place
" dummy.txt
为什么会得到command i expects \ followed by text
?或者如何在Mac上使用双引号将文本添加到特定行?
$ sed "2i\\
These are words on\\
multiple lines\\
" input
1
These are words on
multiple lines
2
3
4
5
6
7
8
9
10
您需要转义反斜杠,以便对其sed
进行解析并转义您要转义的原义换行符,sed
而不是shell。
$ sed '2i\
thing' input
有了强引号,所有内容都会按字面传递,因此请sed
参见<2> <i> <literal linefeed>
$ sed "2i\
thing" input
使用弱引号,shell在解析字符串时会得到第一个dib,因此sed
看到<2> <i> <linefeed>
,这是一个语法错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句