假设有文件test.txt,想把test.txt文件第三列含有的good替换为bye,并把替换后的文件保存为test_bye.txt,只需要如下命令。

test.txt

go go good go

my my go good

bye my good bye

test_bye.txt

go go bye go

my my go good

bye my bye bye

awk -F " " '{if ($3==good) $3=bye}1' test.txt > test_bye.txt

  

" "表示test.txt文本间用空格隔开

$3表示第三列,即good,go, good

05-11 15:12