Unable to replace string in AIX ksh shell

My variable contains the following string

I wish to replace \n with "space" so the expected output is:

I understand that the /n is not a new linein this case.

I'm on AIX using ksh shell. Below is all that I tried.

echo $str | sed -e "s#\n# #g";
echo $str | sed -e "s#\n#' '#g";
echo $str | sed -e "s#/\n#' '#g";
echo $str | sed -e "s#/\n# #g";
echo "${str///\n/ }"
echo "${str//\n/ }"
tr '\n' ' ' | echo $str

Unfortunately none of the above attempts helped.

$ echo $str | sed -e 's#\\n# #g';
/fin/app/scripts /fin/app/01/sql

more Parameter2.out
/fin/app/01/scripts\\n/fin/app/01/sql

I tried your suggestion on a new string containing "\\n" which is read from a file.

Unfortunately, I m not able to replace the \\n

Below is what I tried.

echo $str | sed -e 's#\\\\n# #g';

Let me know if I should open a new thread of this ?

$ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g';
/fin/app/scripts /fin/app/01/sql
$ echo '/fin/app/scripts\\n/fin/app/01/sql' > file
$ sed -e 's#\\\\n# #g' file
/fin/app/scripts /fin/app/01/sql
1 Like

Thank you @anbu23. I have posted a new thread further to the problem:

Replace string works on command-line but fails when run from shell script

tr '\n' ' ' <( echo $str )

or

echo $str | tr '\n' ' '