Posted By

noah on 02/05/09


Tagged

regex Shell Bash search commandline grep perl find one-liners


Versions (?)

grep with Perl


 / Published in: Perl
 

A combination of the instructions in the book Minimal Perl and this Perl one-liners page

The general form of the one-liner is:

> perl -wnl -e '/REGEX/ and print $ARGV." $.: $_"; close ARGV if eof' <files>

The example below shows how to print the hex colors that are defined in a Sass source tree.

  1. # search files in a directory
  2.  
  3. perl -wnl -e '/\s#[0-9a-zA-Z]{3,6}\b/ and print $ARGV." $.: $_"; close ARGV if eof' *sass
  4.  
  5. # search a filesystem
  6.  
  7. find . -name "*sass" | xargs perl -wnl -e '/\s#[0-9a-zA-Z]{3,6}\b/ and print $ARGV." $.: $_"; close ARGV if eof'

Report this snippet  

You need to login to post a comment.