We Recommend

Learning Perl Learning Perl
In this smooth, carefully paced course, a leading Perl trainer teaches you to program in the language that threatens to make C, sed, awk, and the Unix shell obsolete for many tasks. This book is the "official" guide for both formal (classroom) and informal learning. It is fully accessible to the novice programmer.


Posted By

noah on 07/04/07


Tagged

regex wrapper Bash commandline hacking perl editing productivity tips diamond tricks


Versions (?)


command-line perl


Published in: Perl 


URL: http://perl.com/pub/a/2004/08/09/commandline.html?page=2

couple of useful snippets from an article I found at Perl.com

  1. #print the result of search-and-replace to the terminal
  2. perl -pe 's/bart/milhouse/g' test.html
  3.  
  4. #search-and-replace, with backup
  5. #leave the suffix off of -i to overwrite
  6. perl -i.bak -pe 's/bart/milhouse/g' test.html
  7.  
  8. #echo the number of lines in a file
  9. perl -lne 'END { print $t } @w = /(\w+)/g; $t += @w' test.html
  10.  
  11. #cat file with line numbers
  12. # -p prints $_ each iteration
  13. perl -pe '$_ = "$. = $_"' test.html

Report this snippet 

You need to login to post a comment.