I am creating sed commands based on input file that has some numbers in it.

When I run a the following command on command prompt, it gives me desired result.
[echo "sed -n '2,$ s/^\(.\{"$i"\}\)\(.*\)$/\1,\2/'"] i.e. value of the variable is replaced and a sed command is generated in a single line.

But when this is run inside a shell script using KSH, the output is generated in two lines.
[echo "sed -n '2,$ s/^\(.\{"$i"\}\)\(.*\)$/\1,\2/'">script1.sh]

script1.sh will read like below:-
sed '2,$ s/^\(.\{

The input file that is being read to replace $i has records like

IFS in the shell script has been set to '_'

Please could someone help.

Hey There,

Are you getting the value of $i during the sed command?

I guess, more clearly, is that the first time?

If that's the case, try defining $i outside of the sed command and the newline should go away when you echo your sed into the file.

If I'm wrong, can you post a little more surrounding code and what OS you're on (For instance, on some versions of Linux, the sed command acts slightly differently)

Best wishes,