Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    71

    Unanswered: SED or AWk to delete lines out of file1 based on values in file2?

    Hello all. I have a big file that I need to delete a number of lines out of. I want to read the values that will determine deletion out of another file, because there are multiple.

    Can someone post an example of a sed or awk script to do this?

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Try something like this:
    Code:
    for pat in $(cat patterns.txt)
    do
      sed "/$pat/d" <bigfile >newbigfile
      mv newbigfile bigfile
    done
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    You could also use grep's -f option...

    grep -vf patternFile yourFile > newFile

  4. #4
    Join Date
    Jan 2004
    Posts
    71

    ..

    Thanks guys. Someone else suggested the grep thing to me and its so elegant and simple that I am totally amazed.

Posting Permissions

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