Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    15

    Unanswered: Deleting end of line

    Hi,

    I am fairly new to using script and sed.

    I have a few hunderd lines of script that I want to delete the last bit from (all lines are different). So far I have been able to match part of the bit that I want to delete, but sed deletes everything past the pattern.

    For example I have something like this:

    text delete_01-this
    text delete_02-this
    text delete_03-this
    text delete_04-this
    text delete_05-this
    text delete_06-this
    text delete_07-this
    text delete_08-this
    text delete_09-this

    which gives me:

    text delete
    text delete
    text delete
    text delete
    text delete
    text delete
    text delete
    text delete
    text delete

    I have tried various things but can't seem to get it right, like the following:

    sed 's/[_$]_*$//' file

    Thanks for any help!
    David

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    If I understand correct you want to delete everything on a line starting from the _ character
    Code:
    sed 's/_\(.*\)//' file

  3. #3
    Join Date
    Feb 2006
    Posts
    15
    Thanks, yes that is what I wanted!

    PS I love sed, works a charm!!

Posting Permissions

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