linux 中sed命令将指定列替换为特定的内容

 

001、

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt
d       iy      5f      er
sd      34      d8      3f
dg      dg      xe      j7
[root@pc1 test]# sed 's/\S\+/KKK/' a.txt             ## 第一列
KKK     iy      5f      er
KKK     34      d8      3f
KKK     dg      xe      j7
[root@pc1 test]# sed 's/\t\S\+/\tKKK/1' a.txt        ## 第二列
d       KKK     5f      er
sd      KKK     d8      3f
dg      KKK     xe      j7
[root@pc1 test]# sed 's/\t\S\+/\tKKK/2' a.txt        ## 第三列
d       iy      KKK     er
sd      34      KKK     3f
dg      dg      KKK     j7
[root@pc1 test]# sed 's/\t\S\+/\tKKK/3' a.txt        ## 第四列
d       iy      5f      KKK
sd      34      d8      KKK
dg      dg      xe      KKK

 

posted @ 2023-01-05 09:02  小鲨鱼2018  阅读(2274)  评论(0编辑  收藏  举报