mac上执行sed的编辑 -i命令报错sed: 1: "test.txt": undefined label ‘est.txt’或sed: 1: "2a\test\": extra characters after \ at the end of a command
2016-09-25 23:27
701 查看
问题一
sed编辑命令:【sed -i 's/a/b/g' test.txt】
报错:sed: 1: "test.txt": undefined label 'est.txt'
解决方案:增加一个备份的追加名【sed -i '.bak' 's/a/b/g' test.txt】
原因:mac强制要求备份,否则报错
当然可以不使用其他备份名字,只是用’',就可以只保留一份
sed -i ‘’ ’s/a/b/g’ test.txt
问题二
sed追加命令:【sed -i '' "/a/a\xxx” test.txt】匹配到a字符后追加xxx内容
报错:sed: 1: "2a\test\": extra characters after \ at the end of a command
解决方案:在追加内容前换行,且要用双斜杠\\
sed -i '' "/a/a\\
xxx" test.txt
但是这又有一个新的问题,追加的内容是显示在下一行的前面,没有独立占据一行
使用\\n啊\n什么的都无效,其实只要在字符串后面直接输入\\然后回车换行就有效了,如下图所示。
备注:在某一行前插入用/i,例如在匹配到a的前面一行加入yyy
sed -i '' "/a/i\\
xxx" test.txt
mac上的sed -n之类的与linux系统上使用方法一样
sed编辑命令:【sed -i 's/a/b/g' test.txt】
报错:sed: 1: "test.txt": undefined label 'est.txt'
解决方案:增加一个备份的追加名【sed -i '.bak' 's/a/b/g' test.txt】
原因:mac强制要求备份,否则报错
当然可以不使用其他备份名字,只是用’',就可以只保留一份
sed -i ‘’ ’s/a/b/g’ test.txt
问题二
sed追加命令:【sed -i '' "/a/a\xxx” test.txt】匹配到a字符后追加xxx内容
报错:sed: 1: "2a\test\": extra characters after \ at the end of a command
解决方案:在追加内容前换行,且要用双斜杠\\
sed -i '' "/a/a\\
xxx" test.txt
但是这又有一个新的问题,追加的内容是显示在下一行的前面,没有独立占据一行
使用\\n啊\n什么的都无效,其实只要在字符串后面直接输入\\然后回车换行就有效了,如下图所示。
备注:在某一行前插入用/i,例如在匹配到a的前面一行加入yyy
sed -i '' "/a/i\\
xxx" test.txt
mac上的sed -n之类的与linux系统上使用方法一样
相关文章推荐
- sed: 1: "grep": extra characters at the end of g command----sed on mac
- This page contains the following errors: error on line 1 at column 1: Extra content at the end of t
- XML文件要有根标签(Extra content at the end of the document in file 错误)
- 执行docker ps命令,出现 "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. ..."问题
- 服务器返回出现:error on line 19 at column 1: Extra content at the end of the document
- [vs执行报错] CRT detected that the application wrote to memory after end of heap buffer
- java.lang.ClassFormatError: Extra bytes at the end of class file
- Caused by: java.lang.ClassFormatError: Extra bytes at the end of class file
- PHP - XML parse error: Extra content at the end of the document
- 错误解决:SharePoint Designer 2010编辑后,出现数据源控件未能执行插入命令,data source control failed to execute the insert command
- Qt5:"Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document."错误
- 【FAQ】Mac下,执行sed命令报错:“command c expects \ followed by text”,怎么办?
- 当打开Oracle Jdevelopler 11g时出现"Unable to create an instace of the jave virtual Machine Located at path"错时解决办法
- The notes of How We Test Software At Microsoft(7)
- CRT detected that the application wrote to memory after after the end of heap buffer(这个经常忘掉)
- A internal server error like "stack overflow" can cause the exception of "Validation of viewstate MAC faild"
- WCF error "No end point listening at net.pipe://server name:port/service name that could accept the message
- The notes of How We Test Software At Microsoft(5)
- The notes of How We Test Software At Microsoft(2)
- A potentially dangerous Request.Form value was detected from the client (txtTest="").