Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

I use it for in-place search and replace within files.

perl -pi -e 's/change this/into this/g' filename(s)

-p assumes an input loop around your script. Lines are printed.

-i in-place editing of files

-e may be used to enter a single line of script. Multiple -e commands may be given to build up a multiline script.

Combined with "find" with -exec and/or pipe the filenames into xargs and you can do a global search and replace across a whole tree of files.



Yep, but for that example, sed has a -i too.

Also I recommend adding a backup for inplace edits.

man perlrun recommends -spi.orig




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: