当列3有特定的词时,如何将列1替换为列3 ?

时间:2022-09-08 07:40:51

I have a three column data file which is of the format as below:

我有一个三列数据文件,格式如下:

convicts NP convict
console  JJ <unknown>
apples   NP apple

So, here I would like to have the word console in the place where the word "unknown" is.

所以,在这里,我想把控制台这个词放在单词“unknown”的位置。

PS: It is a huge file which contains the word "unknown" multiple number of times. So, wherever the word "unknown" occurs in the third column, I want it to be replaced by it's corresponding 1st column word.

PS:这是一个包含“未知”一词多次的巨大文件。因此,无论在第三列中出现“未知”这个词,我都希望它被对应的第一列词所取代。

I tried using the command

我试着使用这个命令

awk ' { $3="unknown"; $3=$1; print } ' <FILENAME> 

but this replaces the entire 3rd column with the words of the 1st column. Please help with how I can rectify this. Thanks in advance!

但是这将用第一列的单词替换整个第三列。请帮我纠正一下。提前谢谢!

1 个解决方案

#1


2  

If you want to replace <unknown> with the corresponding lines first column value:

如果要将 替换为对应的行,第一列值为:

awk '$3=="<unknown>"{$3=$1;} {print};' filename

#1


2  

If you want to replace <unknown> with the corresponding lines first column value:

如果要将 替换为对应的行,第一列值为:

awk '$3=="<unknown>"{$3=$1;} {print};' filename