linux 下 sed 用例

全栈 shanhuhai 2418℃ 0评论

创建测试文件

cat > a.txt << END
docker
nl
sed
gearman
nlp
lua
rpm
END

删除3到5行

nl a.txt  | sed '3,5d'

替换3到5行


nl a.txt | sed '3,5c lua'

在第2行加上 “drink tea”

nl a.txt | sed '2a drink tea'

在第2行前面插入 “drink tea”

nl a.txt | sed '2i drink tea'

在文件中搜索 nl,并打印

nl a.txt | sed -n '/nl/p'

在文件忠搜索 nl ,并删除

nl a.txt | sed  '/nl/d'

在文件中搜索包含 a 的行,并将 a 替换为 x,并打印出来
nl a.txt | sed -n ‘/a/{s/a/x/;p}’

转载请注明:大后端 » linux 下 sed 用例

付费咨询
喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址