Regex: Remove lines containing
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?
This is also possible with Notepad++
"Mark"
tab. 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.
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.
Easy task with grep
:
grep -v help filename
Append > newFileName
to redirect output to a new file.
Update
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 match filename
is the name of the input file >
redirects the output to the following item newFileName
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.
上一篇: 究竟是什么。*? 用正则表达式吗? “。*?([一个
下一篇: 正则表达式:删除包含的行