sed Doesn't Trim Whitespace from EOL

  • hauerwas

    hauerwas - 2004-07-29

    I'm trying to use the Unxutil sed to trim whitespace prior to EOL.  The command I'm using is:

    sed -e "s/ *$//g" temp.txt > temp2.txt

    Files are CRLF under DOS.  Is this my problem, that it's CRLF and it's looking for Unix EOL?


    Adam Hauerwas

    • hauerwas

      hauerwas - 2004-07-29

      Okay, I got it.  It's a platform difference (CRLF vs. LF).

      sed -e "s/ *.$//g"

      does work.  The problem is that this coerces CRLF to LF.  I've tried "sed -n p" and that displays to the screen correctly, but if I redirect it to an output file I still only get LF delimiting.

      So long as I know a character that will be in every line of the file, I can pipe the sed output to NT "find" and it puts the correct EOL on the lines.

      Any other thoughts?


    • hauerwas

      hauerwas - 2004-07-29

      Uh oh -- one more stray thought.

      sed -e "s/ *.$//" only works so long as you know that the file *is* CRLF beforehand.  If it's LF you're screwed b/c you wind up munging whatever the terminal character on the line is...

      Are there parameters you can pass (under DOS) to specify or detect whether you have CRLF or LF delimited files?


    • Paul Massey

      Paul Massey - 2008-05-01

      I have been trying for the longest time to get sed to find the EOL.  I just wanted to append some data to the end of every line of a file but I can never seem to get SED to understand the end of a line.  Does the period dollar sign mean end of line in DOS?

      • Jason Anderson

        Jason Anderson - 2008-05-01

        This works for me: sed /$/hi/

        Did you check your line endings, as described in the thread you replied to?  I'm not sure what line endings my test file has.

    • Greg

      Greg - 2008-05-02

      Why not just use the character class [[:space:]]?

      Like this:

      echo "line       " | sed 's/[[:space:]]*$//g'

      This will remove any and all spaces up to the EOL.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks