1. 打印两行
grep -A 1 "c_timestamp" a.log
2. 批量增加当前行的下一行
sed -i "/c_timestamp/a field_type:TIMESTAMP" a.log
3. 批量删除匹配行的下一行
sed -i "/c_timestamp/{n;d}" a.log
4. 批量删除匹配行
sed -i "/compare_file \$client_output22219_SNAPSHOT/d" ./a.sh
sed -i "/compare_file \$client_output22219_SNAPSHOT/d" ./a.sh
4. 在匹配行之后插入一行
sed -i "/expect_result2/ a expect_result3=\"\$c_path/expect_binary.log\"" ./*/a.sh
5. 修改匹配行的下一行
sed ’/test/{ n; s/aa/bb/; }’ example—–如果test被匹配,则移动到匹配行的下一行,替换这一行的aa,变为bb,并打印该行,然后继续。
6. 在文件最后一行插入新行
sed -i "$ a server.messageType = text" ./demo.properties
7. 批量修改匹配行
sed -i "/finishrateServer/ s/10.10.10.107/10.94.97.137/g" ./a.conf
8. awk取匹配行 第三列
awk '{if($2~/^1$/)print}' ./a.txt >text.txt