Skip to content

How to replace a string in a file using Perl

How to replace a string in a file using Perl

Answer:

Assume you have a file "test'txt", contains the string "abc", and you want to replace by "def", use the following script

perl -pi -e "s/abc/def/g;" test.txt

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  1. Search and replace string in file using Perl
  2. Replace a string using regular expressions in Perl
  3. Trim a string using Perl
  4. Replace Unicode character using regex with Perl
  5. Remove the last character of a string in Perl

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*