Reputation: 23178
I have a long document of commands. Using Notepad++ or regex, I want to delete all lines containing "help" including keyboard_help, etc.
How can this be done?
Upvotes: 500
Views: 470007
Reputation: 448
You have to do it in two steps.
1. Bookmark the lines having that pattern
Press CTRL + M button. In the find what text box, enter the pattern. Then select the check box labeled as Bookmark Line. Then click the button named "Mark All". Close the dialog box.
2. Delete those bookmarked lines
Press ALT + S(earch) + B(ookmark) + R. Press Enter.
You are done.
Upvotes: 6
Reputation: 60566
If you're on Windows, try findstr
. Third-party tools are not needed:
findstr /V /L "searchstring" inputfile.txt > outputfile.txt
It supports regex's too! Just read the tool's help findstr /?
P.S. If you want to work with big, huge files (like 400 MB log files) a text editor is not very memory-efficient, so, as someone already pointed out, command-line tools are the way to go. But there's no grep on Windows, so...
I just ran this on a 1 GB log file, and it literally took 3 seconds.
Upvotes: 11
Reputation: 92976
This is also possible with Notepad++:
Check Bookmark line (if there is no Mark tab update to the current version).
Enter your search term and click Mark All
Now go to the menu Search → Bookmark → Remove Bookmarked lines
Done.
Upvotes: 1233
Reputation: 4859
Another way to do this in Notepad++ is all in the Find/Replace dialog and with regex:
Ctrl + h to bring up the find replace dialog.
In the Find what:
text box include your regex: .*help.*\r?\n
(where the \r
is optional in case the file doesn't have Windows line endings).
Leave the Replace with:
text box empty.
Make sure the Regular expression radio button in the Search Mode area is selected. Then click Replace All
and voila! All lines containing your search term help
have been removed.
Upvotes: 252
Reputation: 59277
Easy task with grep
:
grep -v help filename
Append > newFileName
to redirect output to a new file.
To clarify it, the normal behavior will be printing the lines on screen. To pipe it to a file, the >
can be used. Thus, in this command:
grep -v help filename > newFileName
grep
calls the grep
program, obviously-v
is a flag to inverse the output. By defaulf, grep
prints the lines that match the given pattern. With this flag, it will print the lines that don't match the pattern.help
is the pattern to matchfilename
is the name of the input file>
redirects the output to the following itemnewFileName
the new file where output will be saved.As you may noticed, you will not be deleting things in your file. grep
will read it and another file will be saved, modified accordingly.
Upvotes: 19
Reputation: 68152
You can do this using sed: sed '/help/ d' < inputFile > outputFile
Upvotes: 14