Replace newlines with literal \n

后端 未结 6 1593
北荒
北荒 2020-12-05 17:17

This stackoverflow question has an answer to replace newlines with sed, using the format sed \':a;N;$!ba;s/\\n/ /g\'.

This works, but not for special characters like

6条回答
  •  心在旅途
    2020-12-05 17:21

    You could do this using sed and tr:

    sed 's/$/\\n/' file | tr -d '\n'
    

    However this will add an extra \n at the end.

提交回复
热议问题