Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2005
    Posts
    19

    Unanswered: Search Character at the End Of Line?

    Does anyone know how to write a sed command that will delete all lines except lines ending with a particular character - the character is the bar |

    Thanks a lot for your help!

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    sed -ne '/|$/p' file
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Feb 2005
    Posts
    19
    Thank you for the reply. The command didn't seem to alter the file. I entered:

    sed -ne '/|$/p' test.txt

    Is that correct?

    Thanks again

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    that's correct!
    make sure thare'e no spaces/tabs/etc AFTER the trailing pipe.
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  5. #5
    Join Date
    Feb 2005
    Posts
    19
    oh I just realized that. So now I have to get rid of all blank spaces after the |

    There are some spaces that I want to keep within the line so I can't remove all spaces. So I tried this but it doesn't work:

    sed -ne '/| *//p' test.txt

    Any suggestion?

  6. #6
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    # this will get the lines trailing spaces AFTER the last pipe
    sed -ne '/| *$//p' test.txt

    #this will do the above AND remove the trailing spaces from the selected lines
    sed -ne '/| *$/s/ *$//p' test.txt

  7. #7
    Join Date
    Feb 2005
    Posts
    19
    i used the first one that you wrote - it worked perfectly!

    Thank you

Posting Permissions

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