想要打印基於$ 1和$ 3組合的所有最小值。如果有兩行或更多行可用 作爲具有$ 1和$ 3的唯一組合的最小值,則需要打印所有行。例如,具有出現兩次的最小值$ 3-「10」的$ 1-「Abc」,即Abc,yyy,10,aaa和Abc,ttt,10,aaa。輸入文件未按任何順序排序。awk打印每個類別的所有最小值
INPUT.TXT
Country,Desc,Amount,Details
Abc,xxx,20,aaa
Abc,yyy,10,aaa
ghi,ttt,25,ccc
Abc,zzz,35,aaa
def,xxx,30,bbb
Abc,ttt,10,aaa
def,yyy,20,bbb
ghi,yyy,25,ccc
def,zzz,45,bbb
ghi,xxx,35,ccc
ghi,zzz,50,ccc
想打印的輸出與標題行沿NR==1 , {print}
期望Output.txt的
Country,Desc,Amount,Details
Abc,yyy,10,aaa
Abc,ttt,10,aaa
ghi,ttt,25,ccc
ghi,yyy,25,ccc
def,yyy,20,bbb
我用兩個命令來獲得所需的輸出,第一個sort
基於$ 1和$ 3的輸入文件,然後是第二個命令awk -F, '!seen[$1]++'
尋找你的建議只是像一個班輪。
這是一個非常甜蜜的awk。 – dawg
非常感謝James Brown – VNA