Perl one liner to delete or replace a line in a file

Delete a matching line from a file:
perl -ni -e 'print unless /pattern/' filename


Replace a matching pattern to another:
perl -pi -e "s/matchingpattern/newpattern/" filename


Remove duplicate lines:
 perl -i -ne 'print unless $seen{$_}++' filename 


Perl options:
-n: while (<>) { ... # your script}
-p: while (<>) { ... # your script } continue { print or die "-p destination: $!\n";}
-i: in place

No comments: