Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Perl's -p command-line switch do?

Tags:

perl

perl -p -i.bak -e 's/search_str/replace_str/g' filename

What do -p, -i.bak s/ and /g mean?

like image 525
Bharath Avatar asked Nov 27 '22 12:11

Bharath


1 Answers

  • -p: assume 'while (<>) { ... }' loop around program and print each processed line too.
  • -i.bak: change the input file (filename) inplace and create the file filename.bak as backup.
  • s in s/: to mark substitution
  • g - make the substitution globally..that is don't stop after first replacement.
like image 200
codaddict Avatar answered Dec 28 '22 00:12

codaddict