mona mona - 2 years ago 156
Perl Question

How to remove particular lines contaning specific symbol using AWK / perl

I have multiple files with .txt extention, In all files some lines having "?" symbol, so how to remove those whole line in all files using single AWK/perl command

I used following command:

perl -pi -e "s/\?//g" *.txt

but it remove only ? symbol not whole line, so please help me to remove whole line contain "?" symbol.

Answer Source

One perly way:

perl -ni -e 'next if /\?/; print' *.txt

The -n flag loops over the file the same way as -p, however it doesn't automatically print the line; it leaves that responsibility to you. So what we do is loop over all lines, skip the ones with a ? with next(), and print all others.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download