我有一个非常具体的问题,我想搜索包含第一个单词的行 *Contro_Contact 在 file1 中,当它被发现时,我想用来自 anthor file2 的另一行替换那 2 行之后的行,以便从文件 2 自动更改参数
*CONTROL_CONTACT
$# slsfac rwpnal islchk shlthk penopt thkchg orien enmass
0.100000 0.000 2 1 4 0 1 0
输出可能是
*CONTROL_CONTACT
$# slsfac rwpnal islchk shlthk penopt thkchg orien enmass
0.2340000 0.000 2 1 4 0 1 0
我从另一个文件中更改了行,所以这不是问题。
我会等待专家的建议。
最佳答案
awk 'N != 0 || $0 != "*CONTROL_CONTACT"
N == 0 && $0 =="*CONTROL_CONTACT"{
N = 1; print; getline; print
getline; getline < "file2"; print}' file1
关于linux - 在文件中搜索字符串并使用 awk 更改下一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9291290/