首页 > 系统服务 > 详细

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-26 00:48:40      阅读:1273      评论:0      收藏:0      [点我收藏+]
问题一
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系统上使用方法一样
 

mac上执行sed的编辑 -i命令报错sed: 1: "test.txt": undefined label ‘est.txt’或sed: 1: "2a\test\": extra characters after \ at the end of a command

原文:http://www.cnblogs.com/meitian/p/5907562.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!