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

前端 未结 9 1926
囚心锁ツ
囚心锁ツ 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:16

    How about to use xargs?

    for your case

    $ cat foo.txt | sed 's/$/, /' | xargs
    

    Be careful about the limit length of input of xargs command. (This means very long input file cannot be handled by this.)

提交回复
热议问题