I have a text file named. output.txt.
Now I want to delete all row start with "abc xyz " in this file.
How to do that in Ubuntu using Perl or Python ?
$ perl -ne 'print unless /^abc xyz/' textfile.txt >output
-n command line flag wraps a loop around the program. It reads a file line by line. The current line ends up in
-e allows us to put a program on the command line. That's the stuff in single quotes
Now the program
$_ (that's the current line) imlicitly
$_ (that's still the current line) implicitly matches (
m//, but the
m is optional) the pattern. The
^ is the start of the string anchor, the rest is literal.
Then send the output somewhere else with the
output is the target filename.