Results 1 to 6 of 6

Thread: UNIX Shell Change the EOL (\n newline) by nothing - remove new line

  1. #1
    Member permalac's Avatar
    Join Date
    May 2008
    Location
    barcelona
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default UNIX Shell Change the EOL (\n newline) by nothing - remove new line

    I have a txt file like this:

    hello,
    hi,
    word3,



    and I would like to get only one line, what would you do?


    sed 's/$//g' whas my chance, and did not work.


    thanks .

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 804 Times in 511 Posts
    Rep Power
    10

    Default

    Sorry, but I don't get your question. Can you provide more details?
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Member permalac's Avatar
    Join Date
    May 2008
    Location
    barcelona
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default sed perl shell command to remove newline (\n) from a file

    sure.



    I have this :

    word1,
    word2,
    word3,
    And I want this:

    word1,word2,word3,
    Last edited by nixcraft; 14th May 2008 at 01:05 AM.

  4. #4
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,513
    Thanks
    17
    Thanked 804 Times in 511 Posts
    Rep Power
    10

    Default

    Try following shell script
    Code:
    #!/bin/bash
    INPUT="/path/to/file"
    while read line
     do
     echo -n $line
    done < $INPUT
    You can also try tr
    Code:
    tr -d '\n\' < /path/to/file
    Perl version
    Code:
    perl -e 'while (<>) { if (! /\|$/ ) { chomp; } print ;}' </path/to/input/file
    GNU sed version (may not work with UNIX / BSD sed):
    Code:
    sed ':a;N;$!ba;s/\n//g' < /path/to/file
    Use any one of the above method
    Last edited by nixcraft; 14th May 2008 at 01:05 AM.
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  5. The Following User Says Thank You to nixcraft For This Useful Post:

    permalac (3rd February 2011)

  6. #5
    Member permalac's Avatar
    Join Date
    May 2008
    Location
    barcelona
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    OOOK, many thanks.

    I like the sed one, .

  7. #6
    Member
    Join Date
    Feb 2008
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    7

    Default

    Code:
    paste -s -d '\0' file

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 13th October 2010, 08:17 PM
  2. unix shell on windows xp
    By chiku in forum Solaris/OpenSolaris
    Replies: 4
    Last Post: 7th March 2008, 03:17 PM
  3. Replies: 1
    Last Post: 11th February 2008, 05:20 PM
  4. Linux UNIX SFTP in a Shell Script
    By Nishanthhampali in forum Shell scripting
    Replies: 1
    Last Post: 30th January 2008, 01:16 PM
  5. How to change the login shell for Linux user
    By chimu in forum Getting started tutorials
    Replies: 0
    Last Post: 26th January 2007, 07:20 PM

Tags for this Thread

Posting Permissions

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