Concise and portable “join” on the Unix command-line

前端 未结 9 1940
囚心锁ツ
囚心锁ツ 2020-11-29 00:53

How can I join multiple lines into one line, with a separator where the new-line characters were, and avoiding a trailing separator and, optionally, ignoring empty lines?

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 01:21

    My answer is:

    awk '{printf "%s", ","$0}' foo.txt
    

    printf is enough. We don't need -F"\n" to change field separator.

提交回复
热议问题