根据另一列值更改一列 [英] Change a column based on another column value
本文介绍了根据另一列值更改一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含数百条这样的记录的文件
I have a file with hundreds of records like this
100,502030,0,444,RSVYU,10
101,501412,1,555,DDGTH,11
102,502269,0,222,DDERF,60
103,508877,2,111,SDEFV,23
如果第3 列的值是 0 000 替换第4 列的值>
How to replace the value of the 4th column with 000 if the value of the 3rd column is 0
我研究了很多,却找不到解决方案.到目前为止,我已经知道了
I researched a lot and couldn't find a solution. So far I got this
cat testfile.txt | sed -n -r 's/^[0-9]*,[0-9]*,0/000/p'
但是它代替了第一部分
推荐答案
使用awk:
awk 'BEGIN{FS=OFS=","} $3=="0" {$4="000"}1' file
FS
:输入字段分隔符
FS
: input field separator
OFS
:输出字段分隔符
输出:
100,502030,0,000,RSVYU,10
101,501412,1,555,DDGTH,11
102,502269,0,000,DDERF,60
103,508877,2,111,SDEFV,23
这篇关于根据另一列值更改一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文