在 Bash 脚本 w/o SED 中的特定文件行后添加文本
Adding Text After Specific Line of File in Bash Script w/o SED
我正在尝试在特定行下添加一行,让我们说 [BELOW HERE] 并且不使用 SED。执行此操作的最佳替代方法是什么?
我试过使用 SED,但是创建脚本的机器不支持它。
sed --in-place "/^\[BELOW HERE\]/a BLabla=Database toolSomething" file
/a = 追加
使用awk
及其gsub
函数。
awk '/BELOW HERE/{gsub(/$/,"&\nTHIS IS NEW LINE ADDED HERE")}1' input
I am trying to append a line under a specific line,
lets say [BELOW HERE] and without using SED.
THIS IS NEW LINE ADDED HERE
What is the best alternative way to do this?
不确定您不想使用 sed
:这是一个 sed
解决方案:
sh-4.1$ sed '/BELOW HERE/a\
"THIS IS NEW LINE ADDED HERE"' input
I am trying to append a line under a specific line,
lets say [BELOW HERE] and without using SED.
"THIS IS NEW LINE ADDED HERE"
What is the best alternative way to do this?
sh-4.1$
输入文件:
cat input
I am trying to append a line under a specific line,
lets say [BELOW HERE] and without using SED.
What is the best alternative way to do this?
您不需要 awk
、sed
或任何其他第三方内置插件来完成这项琐碎的任务。您可以使用 UNIX
天后所有主要发行版中可用的 ed
编辑器,
printf '%s\n' 'g/[BELOW HERE]/s/\r/BLabla=Database toolSomething
/g' w q | ed -s file
我正在尝试在特定行下添加一行,让我们说 [BELOW HERE] 并且不使用 SED。执行此操作的最佳替代方法是什么?
我试过使用 SED,但是创建脚本的机器不支持它。
sed --in-place "/^\[BELOW HERE\]/a BLabla=Database toolSomething" file
/a = 追加
使用awk
及其gsub
函数。
awk '/BELOW HERE/{gsub(/$/,"&\nTHIS IS NEW LINE ADDED HERE")}1' input
I am trying to append a line under a specific line,
lets say [BELOW HERE] and without using SED.
THIS IS NEW LINE ADDED HERE
What is the best alternative way to do this?
不确定您不想使用 sed
:这是一个 sed
解决方案:
sh-4.1$ sed '/BELOW HERE/a\
"THIS IS NEW LINE ADDED HERE"' input
I am trying to append a line under a specific line,
lets say [BELOW HERE] and without using SED.
"THIS IS NEW LINE ADDED HERE"
What is the best alternative way to do this?
sh-4.1$
输入文件:
cat input
I am trying to append a line under a specific line,
lets say [BELOW HERE] and without using SED.
What is the best alternative way to do this?
您不需要 awk
、sed
或任何其他第三方内置插件来完成这项琐碎的任务。您可以使用 UNIX
天后所有主要发行版中可用的 ed
编辑器,
printf '%s\n' 'g/[BELOW HERE]/s/\r/BLabla=Database toolSomething
/g' w q | ed -s file