[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-418bdd332100


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-418bdd332100