0

I have the string below stored in my database column:

"Your ack was rejected due to the following reason: \n -- Invalid code received. \n \n Please correct the error and resend."

\n is the new line character where I want to split the line.

Expected output:

"Your ack was rejected due to the following reason:
-- Invalid code received.

Please correct the error and resend it."

Please suggest unix/sed command

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • Try this https://unix.stackexchange.com/questions/140763/replace-n-by-a-newline-in-sed-portably – souser Aug 24 '20 at 00:59
  • Does this answer your question? [replace \n with newline in awk](https://stackoverflow.com/questions/24574489/replace-n-with-newline-in-awk) – Benjamin W. Aug 24 '20 at 03:44

2 Answers2

0
echo $STRING| sed 's/\\n/\n/g

This worked!

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
0

It is possible to enable interpretation of backslash escapes with the echo -e option. Given that the string may contain special characters, important to wrap it in quotes. No need to use Unix utilities like sed or awk

STRING=...
echo -e "$STRING"
dash-o
  • 13,723
  • 1
  • 10
  • 37