I cannot figure out how to replace \n in text with new lines using sed (sed) or awk (gawk). For example, I would like to have the sed or awk command replace
hello world\nI am from Mars\n
by
hello world
I am from Mars
I cannot figure out how to replace \n in text with new lines using sed (sed) or awk (gawk). For example, I would like to have the sed or awk command replace
hello world\nI am from Mars\n
by
hello world
I am from Mars
 
    
     
    
    I found the answer at https://unix.stackexchange.com/questions/140763/replace-n-by-a-newline-in-sed-portably:
awk '{gsub("\\\\n","\n")};1' filename
 
    
    With GNU sed:
sed 's/\\n/\n/g' file
With bash parameter expansion:
var='hello world\nI am from Mars\n'
echo "${var//\\n/$'\n'}"
