linux awk命令实现批量列的字符串替换

1、直接测试

root@DESKTOP-1N42TVH:/home/test# ls
test.txt
root@DESKTOP-1N42TVH:/home/test# cat test.txt  ##测试数据
a 3 3 a 3 3
s 1 j s 1 j
z c m z c m
q e i q e i
3 4 k 3 4 k
h f 3 h f 3
root@DESKTOP-1N42TVH:/home/test# awk '{for(i = 4; i <= NF; i++) if($i == 3) {$i = "xxx"} {print $0}}' test.txt  ## 将第4列至最后一列的3替换为xxx
a 3 3 a xxx xxx
s 1 j s 1 j
z c m z c m
q e i q e i
3 4 k xxx 4 k
h f 3 h f xxx

 

posted @ 2022-01-03 20:46  小鲨鱼2018  阅读(525)  评论(0编辑  收藏  举报