I'm trying to use the sed command to replace a string in an IFS text file with another string that contains a line feed character ( ). Everything works fine except the line feed character. Any idea how I might be able to get the line feed ( ) to work? Below is what I've tried:
- The IFS text file name is test.txt. Below is the content of this file:
&1
- I ran the following command in an RPGLE program to replace the &1 with the text of "Line 1 Line 2", expecting that the will get translated into the carriage return and line-feed characters
QSH CMD('sed -e "s?&1? Line 1
Line 2 ?g" test.txt > test.out')
- The string replacement works, except the line feed ( ) charater. The result file, test.out, looks like below. The is being translated to character n:
Line 1 n Line 2
- I've also tried below and none of them works:
QSH CMD('sed -e "s?&1? Line 1 \
Line 2 ?g" test.txt > test.out')
QSH CMD('sed -e "s?&1? Line 1 \\n Line 2 ?g" test.txt > test.out')
question from:https://stackoverflow.com/questions/65924677/how-to-use-handle-line-feed-in-sed-command