简体   繁体   中英

How can we program this in UNIX shell scripting?

I have a flat file with N columns.

The Nth column contains word 'abc' several time at different rows.

How can I replace this word 'abc' with 'def'.

The output file should contain the same data till the 'N-1' columns, only in the Nth column the multiple occurences of the word 'abc' should be changed to 'def'.

Please advise on how to acheive this.

Regards, Srihari

awk

awk 'BEGIN{FS=OFS=":"}{$NF=($NF~/abc/)?"def":$NF}1' your_file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM