If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Ho to remove new line char from a string

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-22-08, 23:33
sreedivia sreedivia is offline
Registered User
 
Join Date: Oct 2008
Posts: 7
Ho to remove new line char from a string

Hi
Can anyone tell me how can i remove new line character from a string.
My requirement is to read a line from a file and store it to a string.
read line
string1=$line
read line
string2=$line
echo $string1$string2

The result i am getting in different line. i want the output in the same line.
I think a newline char is getting inserted into each string.How can i remove it?
Reply With Quote
  #2 (permalink)  
Old 10-23-08, 10:30
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,452
Code:
sed '$!N;s/\n//' yourfile
Reply With Quote
  #3 (permalink)  
Old 10-23-08, 18:42
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
This is what I just did:
Code:
ls | wc -l | xargs echo -n
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 10-23-08, 22:42
sreedivia sreedivia is offline
Registered User
 
Join Date: Oct 2008
Posts: 7
Thanks for yor help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On