Text-Formatting
如何將三行合二為一,用逗號隔開
如何轉這個文本:
From: "anonymous" <sip:anonymous@test.com>;tag=1c1969267918 Call-ID: 3227998302912020104951@192.168.1.10 Max-Forwards: 70 From: "anonymous" <sip:anonymous@test.com>;tag=1c6447025742 Call-ID: 1426914846291202010505@192.168.1.10 Max-Forwards: 70
進入這個:
From: "anonymous" <sip:anonymous@test.com>;tag=1c1969267918, Call-ID: 3227998302912020104951@192.168.1.10, Max-Forwards: 70 From: "anonymous" <sip:anonymous@test.com>;tag=1c6447025742, Call-ID: 1426914846291202010505@192.168.1.10, Max-Forwards: 70
除非預期輸出中逗號後的單個空格非常重要:
$ sed 's/^[[:blank:]]*//' file | paste -d, - - - From: "anonymous" <sip:anonymous@test.com>;tag=1c1969267918,Call-ID: 3227998302912020104951@192.168.1.10,Max-Forwards: 70 From: "anonymous" <sip:anonymous@test.com>;tag=1c6447025742,Call-ID: 1426914846291202010505@192.168.1.10,Max-Forwards: 70
這首先用於
sed
刪除輸入文件中每一行的初始空白,然後使用paste
, 將結果行分佈在三列中,並以逗號作為分隔符。