文章の整形なんかで何かと便利なsed。
よくありがちなパターンは、予め登録されてたりするので便利に使わせてもらいましょう。
$ cat sample.txt This is my dog, whose name is Frank. This is my fish, whose name is George. This is my goat, whose name is Adam.
なんて文章があった場合、
オプションの”N”を使うと
$ cat sample.txt | sed -e "N;s/\n//g" This is my dog, whose name is Frank. This is my fish,whose name is George. This is my goat, whose name is Adam.
てな感じで、二行分を一行にまとめる際、すっきり書く事ができます。
参考もと
cat list | sed -e "N;N;s/\n/,/g" > list.csv # Collapse groups of 3 lines to 1 line and seperate the values by commas #guestweek
— Command Line Magic (@climagic) 2015, 7月 15
sed - Wikipedia, the free encyclopedia