更换比赛第一次出现与SED [英] Replacing first occurance of a match with sed
本文介绍了更换比赛第一次出现与SED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做一个查找和使用sed替换,替换BASH变量 $ A
(当一个新行的开始)与BASH变量 $ b
:
I am doing a find and replace with sed, replacing the BASH variable $a
(when at the start of a new line) with the BASH variable $b
:
sed -i "s#^$a#$b#" ./file.txt
本替换所有比赛为 ^ $ A
。我怎么能只更换中第一次出现一个^
整个文件中?
This replaces all matches for ^$a
. How can I replace only the first occurrence of ^a
within the entire file?
推荐答案
这应该工作:
sed -i "0,/^\$a/s//\$b/" ./file.txt
//www.grymoire:
您可以在 HTTP浏览更多有关此.COM /的Unix / Sed.html#TOC-UH-29
You can read more about this at http://www.grymoire.com/Unix/Sed.html#toc-uh-29
这篇关于更换比赛第一次出现与SED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文