Search code examples
textsedgrepeditorfindstr

SED or other editor - remove strings from file on Windows


I need to find a string in a textfile, delete the line containing it, and save the file. The string is found (read from) another textfile, containing hundreds of different strings, one per row. The process is to go on from the first to the last string in the file.

Any (hopefully easy to use) text editors (on Windows OS) recommended ? To achive the task.

I am not into serious day-to-day editing. So I'd be ever so happy if the task could be accomplished with a easy-to-use but still reliable editor.

Thanks a bunch, Frank


Solution

  • On unix/linux/cygwin:

    grep -v -f pattern_file unmodified_file > new_file

    Remove all lines containing the patterns in pattern_file from unmodified_file, write to new_file.

    grep -v outputs lines not matching any pattern. -f reads patterns from a file.

    On windows this appears equivalent to running this at the command prompt:

    FINDSTR /V /G:pattern_file unmodified_file > new_file

    That's it. If you already have the two source files, it's a one-liner.

    pattern_file is going to be whitespace and case sensitive unless you delve into other options, which are described with FINDSTR /?