output of echo command has an unwanted newline character

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 1
Reputation: cliodna is an unknown quantity at this point 
Solved Threads: 0
cliodna cliodna is offline Offline
Newbie Poster

output of echo command has an unwanted newline character

 
0
  #1
Aug 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: output of echo command has an unwanted newline character

 
0
  #2
Aug 4th, 2008
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
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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum


Views: 2276 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC