Quantcast
Viewing latest article 4
Browse Latest Browse All 8

Answer by Ed Morton for Replace newlines with literal \n

Is this what you're trying to do?

$ cat fileabc$ awk '{printf "%s\\n", $0}' filea\nb\nc\n$

or even:

$ awk -v ORS='\\n''1' filea\nb\nc\n$

Run dos2unix on the input file first to strip the \rs if you like, or use -v RS='\r?\n' with GNU awk or do sub(/\r$/,""); before the printf or any other of a dozen or so clear, simple ways to handle it.

sed is for simple substitutions on individual lines, that is all. For anything else you should be using awk.


Viewing latest article 4
Browse Latest Browse All 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>