Replace newlines with literal \n

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

    This should work with both LF or CR-LF line endings:

    sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' file
    

提交回复
热议问题