Perl – translate sed to perl

perlsedsolaris

The following command work fine on Solaris ( delete line only if last character is ":" )

 sed -e '/:$/d' < foo > foo.new

how to do the same in perl ? ( the reason for that because I not want to create a new file )

  perl -i -pe 's/:$/d' foo
  Substitution replacement not terminated at -e line 1.

Best Answer

Something similar to:

perl -ne 'print unless /:$/'
perl -ne 'print if !/:$/'
perl -ne '!/:$/ && print'

Note that both sed -i and perl -i work by creating a temporary file and replacing the original. If you want to avoid that, too, use ed:

ed file <<'EOF'
g/:$/d
wq
EOF