Huy Trần Huy Trần - 10 days ago 5x
Perl Question

how to delete all row start with "abc xyz " in a text file using perl or python

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

The -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 prints $_ (that's the current line) imlicitly unless $_ (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, where output is the target filename.