更改AWK中的字段

时间:2013-09-11 13:32:43

标签: awk

Basicall这是我在awk中需要做的事情: **

# Get fields 10, 11 & 12 from a record and check whether 10 = "No Name" & if 11=12
# if 11=12 then blank 11. Also blank anything with "No Name"...

**

我的输入是这样的:

UPRN|ENDDATE|X|Y|REL|USRN|SAON|PAON|PAONB|STREETf|LOCAL|TOWN
4534|Y      |X| |2  |1123|1   |yes |no   |NO NAME|CHORL|CHORL
3456|N      | |Y|2  |1445|3   |no  |no   |NO NAME|LANCS|LANCS
3457|Y      |X|Y|1  |1456|44  |no  |no   |NO NAME|MANCS|BIRMI

如果与10美元相同,我将如何消除掉10美元,然后消除11美元

提前致谢

到目前为止,我有:

BEGIN{

FS= "|"

}

{

if($10 == "NO NAME" && $11==$12){
    $10=="";
    $11=="";
   }


print $0 > "testing.txt";

}
End

1 个答案:

答案 0 :(得分:2)

awk -F'|' 'BEGIN{OFS="|"}$10=="NO NAME" && $11==$12{$10=""; $11="";}{print $0}'  
filename>testing.txt