我需要通过shell脚本注释一个与模式完全匹配的文件
我有一个文件,里面有一些数据,比如:
hello123
123hello
hello1
11hello
hello11
hello122
我需要评论一个完全匹配的模式行。
例如,我需要从给定的文件中注释“hello1”,然后文件内容必须如下
hello123
123hello
# hello1
11hello
hello11
hello122
避免使用正常模式匹配的另一行注释。
最佳答案
你可以用sed。。
sed 's/^hello1$/# &/' file
或
sed '/^hello1$/s/^/# /' file