| | |
output of echo command has an unwanted newline character
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 0
Hi,
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/^\(.\{
12\}\)\(.*\)$/\1,\2/'
The input file that is being read to replace $i has records like
12_
8_
IFS in the shell script has been set to '_'
Please could someone help.
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/^\(.\{
12\}\)\(.*\)$/\1,\2/'
The input file that is being read to replace $i has records like
12_
8_
IFS in the shell script has been set to '_'
Please could someone help.
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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,
Mike
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,
Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: Email attachment and add text inside the mail
- Next Thread: Please Help!!!
Views: 2276 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





