Roland Turner

about | contact

Perl in-place deletion

I've long known about "perl pie" to make one-liner in-place edits of lines (perl -p -i -e"s/old/new/"), but didn't know how to handle deletion of selected lines. Here's a solution (to delete all lines starting with "stage:"):

grep -lirZ ^stage: . | xargs -0 -L 1 perl -n -i -e'print unless /^[sS]tage:/'

(thanks)