简体   繁体   English

我们如何在UNIX Shell脚本中对此进行编程?

[英]How can we program this in UNIX shell scripting?

I have a flat file with N columns. 我有N列的平面文件。

The Nth column contains word 'abc' several time at different rows. 第N列在不同的行中多次包含单词“ abc”。

How can I replace this word 'abc' with 'def'. 如何将“ abc”一词替换为“ 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'. 直到“ N-1”列之前,输出文件应包含相同的数据,仅在第N列中单词“ abc”的多次出现应更改为“ def”。

Please advise on how to acheive this. 请告知如何实现此目的。

Regards, Srihari 问候,斯里哈里

awk

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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