Article 54XWB [SOLVED] [BASH / SED] sed executed in script does not work

[SOLVED] [BASH / SED] sed executed in script does not work

by
czezz
from LinuxQuestions.org on (#54XWB)
This is an example input file:
Code:cat test.input
9fcfdec4-58a9-4612-b80a-741669bd485d\nfa17fd04-80e1-44c1-bd5e-418bdd332100\nfa17fd04-80e1-44c1-bd5e-418bdd332100When I use following "sed" on it, it works as expected (each \n is replaced by .)
Code:# cat test.input | sed -r 's/[\\n]+/./g'
9fcfdec4-58a9-4612-b80a-741669bd485d.fa17fd04-80e1-44c1-bd5e-418bdd332100.fa17fd04-80e1-44c1-bd5e-418bdd332100BUT, if I try to execute it as script, it fails... what am I doing wrong???

Code:cat script.sh
-------------
#!/bin/bash
X=`cat test.input | sed -r 's/[\n]+/./g'`
echo $X

# ./script.sh
9fcfdec4-58a9-4612-b80a-741669bd485d\nfa17fd04-80e1-44c1-bd5e-418bdd332100\nfa17fd04-80e1-44c1-bd5e-418bdd332100latest?d=yIl2AUoC8zA latest?i=Sn9K1DO1DE0:GO-zIz2sN08:F7zBnMy latest?i=Sn9K1DO1DE0:GO-zIz2sN08:V_sGLiP latest?d=qj6IDK7rITs latest?i=Sn9K1DO1DE0:GO-zIz2sN08:gIN9vFwSn9K1DO1DE0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments