How do i delete all trailing spaces from a file using sed?



  • Man page for sed: https://www.lightnetics.com/post/3334

    Sample file use for this, the dollars signs denote the end of the line, and show a space before the end of the line.

    cat -A linefile 
    This is line one $
    1000$
    This is line two $
    2000$
    This is line three $
    

    Use this:

    $ sed 's/ *$//' linefile | cat -A 
    

    Result, of course the $ signs are not part of the output, this is just to show the spaces were removed.
    This is line one$
    1000$
    This is line two$
    2000$
    This is line three$



© Lightnetics 2024