只替换文本文件中的第一个串

sed -i '0,/oldstring/s/oldstring/newstring/' file

只替换文本文件中第一次某个串后的内容, 把第一个title后卖弄的"abcdefg"替换成"hello",原始文本如下

12445676
title abcdefg
cotent test11111
title 1234567

方法

sed '0,/title/ s/\(title \).*/\1hello/' file

 

相关文章:

  • 2021-09-01
  • 2021-10-03
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
相关资源
相似解决方案