Results 1 to 3 of 3

Thread: Can I use SED to search file and remove txt

  1. #1
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Can I use SED to search file and remove txt

    Hi everyone,

    If I use the command:

    grep some_special_filtering_word_here some_file_name >somenewfile.txt

    It goes in a file, finds the line with the filter word you stipulate and then copies that entire line to another file.

    That's exactly what I want to do, but instead of copy, I want to remove that line/txt. I have a unique word that I will put in the line so it can be easily distinguished from all other lines that might be in the file.

    How can I remove the text and not just copy it.

    Is this a sed thing? If so, can anyone show me how this would be done?
    -----------------------------------------------------------
    Here's an example file with text just to make this easy.

    File name is : test.txt and content is:

    This is a test
    If this works - Yahoo!
    Would be great if I could get this to work


    In the test.txt file the line to remove has the key/filter word of Yahoo!

    Thank you in advance...

  2. #2
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Can I use SED to search file and remove txt

    Quote Originally Posted by mdpalow View Post
    In the test.txt file the line to remove has the key/filter word of Yahoo!
    Code:
    sed '/Yahoo/d' file > temp
    mv temp file
    or if your sed supports the -i option
    Code:
    sed -i '/Yahoo/d' file

  3. #3
    Join Date
    Oct 2007
    Beans
    832
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Can I use SED to search file and remove txt

    Man, I love this forum! You guys/gals are great.

    Thanks VERY much ghostdog74; worked first time.

Bookmarks

Posting Permissions

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