SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2008
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Delete lines from text file after copying to a another file

    Hi,

    vi test.txt

    Code:
    sun
    sun
    moon
    star
    moon
    Now when I execute the command,

    cat test.txt | grep sun > sun.txt

    text "sun" is copied to a file.

    I need a help how to delete the lines which has "sun" from text.txt and save the file

  2. #2
    SitePοint Troll disgracian's Avatar
    Join Date
    Aug 2006
    Location
    Samsara
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use grep's inverse option and redirect back into the file:

    cat test.txt | grep -v sun > test.txt

    Cheers,
    D.

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,085
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    To sum up:

    cat test.txt | grep sun > sun.txt && cat test.txt | grep -v sun > test.txt
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •