Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    7

    Unanswered: 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?

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Code:
    sed '$!N;s/\n//' yourfile
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    This is what I just did:
    Code:
    ls | wc -l | xargs echo -n
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  4. #4
    Join Date
    Oct 2008
    Posts
    7
    Thanks for yor help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •