How to concatenate multiple lines of output to one line?

前端 未结 11 1365
失恋的感觉
失恋的感觉 2020-12-04 07:08

If I run the command cat file | grep pattern, I get many lines of output. How do you concatenate all lines into one line, effectively replacing each \"\\n

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 07:59

    Probably the best way to do it is using 'awk' tool which will generate output into one line

    $ awk ' /pattern/ {print}' ORS=' ' /path/to/file
    

    It will merge all lines into one with space delimiter

提交回复
热议问题