Is there a simple way to remove the same line of text from a folder full of text documents at the command line?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
- Null-terminated string, opening file for reading
I wrote a Perl script for this:
Note that it removes lines based on a regex. If you wanted to do exact match, the inner
foreach
would look like:If your version of sed allows the
-i.bak
flag (edit in place):If not, simply put it in a bash loop:
To find
a pattern
and removethe line containing the pattern
below command can be usedExample : if you want to remove the line containing word
sleep
in all thexml
filesNOTE : Be careful before choosing a pattern as it will delete the line recursively in all the files in the current directory hierarchy :)
This tells perl to loop over your file (-n), edit in place (-i), and print the line if it does not match your regular expression.
Somewhat related, here's a handy way to perform a substitution over several files.
Consider grep -v:
Grep -v shows all lines except those that match, they go into a temp file, and then the tmpfile is moved back to the old file name.