例如: file1包含:
This is an example.
This is Sed example.
This is an example.
我想创建一个像:
这样的文件This is an example.
This is Sed example.
This is awk example.
This is an example.
并且它应该在文件中的任何位置找到关键字:sed
,它应该将sed
更改为awk
并使用原始行下方的更改打印整行。该文件本身
感谢
答案 0 :(得分:3)
这可能适合你(GNU sed):
sed '/\bsed\b/I{p;s//awk/g}' file
这与大小写sed
匹配,打印原始行,然后在整行中替换单词awk
并打印该行。
答案 1 :(得分:0)
awk
版本:
awk '{IGNORECASE=1} $0 ~ /^.*sed.*$/ { print; gsub("sed", "awk" ); print; next}1' file.txt
输出:
This is an example.
This is Sed example.
This is awk example.
This is an example.