Answer by Walter A for Replace newlines with literal \n
With the -zoption you can dosed -z 's/\n/\\n/g' fileorsed -z "s/\n/\\\n/g" file
View ArticleAnswer by RSX for Replace newlines with literal \n
In case it helps anyone, I was searching for the opposite of this question: to replace literal '\'n in a string with newline. I managed to solve it with sed like this:_s="foo\nbar\n"echo $_s | sed...
View ArticleAnswer by voltento for Replace newlines with literal \n
Here is little python script for replacing the '\r\n' with '\r' in directory in a recursive way import os import sysif len(sys.argv) < 2: print("Wrong arguments. Expected path to directory as arg...
View ArticleAnswer by mvr for Replace newlines with literal \n
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.
View ArticleAnswer 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,...
View ArticleAnswer by anubhava for Replace newlines with literal \n
This should work with both LF or CR-LF line endings:sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' file
View ArticleReplace newlines with literal \n
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 \r, \n, etc.What I'm trying to do is to...
View Article