0
因此,我想要做的事情是將一行的第一部分與下一行的第一部分結合起來,每隔一行用冒號分隔。使用sed腳本將當前行的一部分與下一行的一部分隔行
輸入數據在下面,我努力使它工作。
這是我希望它看起來像(希望這樣):
Albania:Armenia
Angola:Antarctica
Argentina:American Samoa
這是輸入:
Albania,EU,http://en.wikipedia.org/wiki/Albania
Armenia,AS,http://en.wikipedia.org/wiki/Armenia
Angola,AF,http://en.wikipedia.org/wiki/Angola
Antarctica,AN,http://en.wikipedia.org/wiki/Antarctica
Argentina,SA,http://en.wikipedia.org/wiki/Argentina
American Samoa,OC,http://en.wikipedia.org/wiki/American_Samoa
Austria,EU,http://en.wikipedia.org/wiki/Austria
Australia,OC,http://en.wikipedia.org/wiki/Australia
Aruba,NA,http://en.wikipedia.org/wiki/Aruba
Azerbaijan,AS,http://en.wikipedia.org/wiki/Azerbaijan
Bosnia and Herzegovina,EU,http://en.wikipedia.org/wiki/Bosnia_and_Herzegovina
Barbados,NA,http://en.wikipedia.org/wiki/Barbados
Bangladesh,AS,http://en.wikipedia.org/wiki/Bangladesh
Belgium,EU,http://en.wikipedia.org/wiki/Belgium
Burkina Faso,AF,http://en.wikipedia.org/wiki/Burkina_Faso
Bulgaria,EU,http://en.wikipedia.org/wiki/Bulgaria
Bahrain,AS,http://en.wikipedia.org/wiki/Bahrain
Burundi,AF,http://en.wikipedia.org/wiki/Burundi
Benin,AF,http://en.wikipedia.org/wiki/Benin
Saint Barthelemy,NA,http://en.wikipedia.org/wiki/Saint_Barthelemy
我已經想出到目前爲止是這樣的,以N獲得下一條線,並且它部分起作用。名字的「垃圾」消失了,但第二名的「垃圾」仍然存在。 (這是一個sed腳本,我必須與所有其他的sed腳本所以沒有AWK或任何運行的sed腳本)
s/,..,.+//
{N
s/\n/:/
p
}
我試圖產生這樣的輸出:
Azerbaijan:Bosnia and Herzegovina,EU,http://en.wikipedia.org/wiki/Bosnia_and_Herzegovina
Barbados:Bangladesh,AS,http://en.wikipedia.org/wiki/Bangladesh
Belgium:Burkina Faso,AF,http://en.wikipedia.org/wiki/Burkina_Faso
Bulgaria:Bahrain,AS,http://en.wikipedia.org/wiki/Bahrain
Burundi:Benin,AF,http://en.wikipedia.org/wiki/Benin
哦,我的天哪,很快就感謝你看起來很完美 – fman
是的,比'paste -d:<(cut -d,-f1 inputfile | sed'$ d')<(cut -d,-f1 inputfile | sed'1d')',upvoted。 –