Replace newlines with literal \n

后端 未结 6 1589
北荒
北荒 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:24

    With the -zoption you can do

    sed -z 's/\n/\\n/g' file
    

    or

    sed -z "s/\n/\\\n/g" file
    

提交回复
热议问题