我有一个包含一些行的文件。Linux Bash:如果条件匹配,则添加前缀到行
我想添加一个前缀到这些行,如果它包含一些关键词。
我该怎么做?谢谢!
例:
我想补充"###"
到线, “Hello
” 在行的开头:
当前这个文件有:
This is the beginning.
Hello I am Simon.
This is a simple line;
Hello Mike.
This is another line.
我想改变此文件到:
This is the beginning.
###Hello I am Simon.
This is a simple line;
###Hello Mike.
This is another line.
请记住使用'sed -i'将更改写入文件并转义特殊字符。 – jgmh
可能更习惯于写'sed'/^Hello/s/^/### /''。 –