File search using regex

Mark Newton newton at atdot.dotat.org
Thu Apr 19 00:03:36 CST 2007


Chris Organ wrote:

> Wondering if someone can assist with regex searches using perl / grep / anything command line. I have lost a severe amount of hair looking for a multi-line search based on exact pattern matching. What I need to do is find this exact header within files within a directory and list them, similar output to using grep -l  ie a list.

All you wordy python programmers are weenies.  What ever happened to
efficient code, I ask you?  Sheesh!

   - mark



#!/usr/bin/perl

# usage:  search.pl filespec
# (filespec can be a list of files, wildcard, etc...)

local $/;

map {
     open FH, "<$_";
     print "$_\n" if grep (/^!D2\nInvoice\n!C\nAUSTALIA EIGHT/, <FH>);
     close FH;
} @ARGV;

# end



--------------------------------------------------------------------
I tried an internal modem,                    newton at atdot.dotat.org
      but it hurt when I walked.                          Mark Newton
----- Voice: +61-4-1620-2223 ------------- Fax: +61-8-82356937 -----


More information about the linuxsa mailing list