[ale] FGrep matches and non matches to two seperate files

Greg Freemyer greg.freemyer at gmail.com
Thu Dec 22 16:45:37 EST 2005


Personally I would do it with a 2 line awk script.  awk will only read
the lines once each.

I think the below script works.

===========
#!/bin/sh

> outfile1
> outfile2
awk '
/pattern/ { print >> "outfile1" }
!/pattern/ { print >> "outfile2" }
' inputfile
========

HTH
Greg

On 12/22/05, Jonathan Chum <jchum at aismedia.com> wrote:
> Sorta of, but that would require one additional process to run to invert the
> list.
>
> For example, I have 25 MB Postfix log file which I've wrote a script that
> extracts the IDs for a specific from <> address, then use fgrep to extract
> the logs specific to that domain.
>
> That process takes about 5 minutes to process 17,000 unique IDs.
>
> If I use the -v invert, then it's another 5 minutes to generate a new list.
> I figure that if fgrep scans a file line by line for a match, there would be
> a way to process those that didn't match into another file to save time from
> re-processing the script.
>
> If there's not a utility to do this, I could write the procedure in Perl
> that replicated what fgrep does, but I wanted to be sure that there isn't a
> utility out there already.
>
> Regards,
> Jonathan Chum
> Senior Developer
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> AIS Media, Inc. - "Passion. Innovation. Expertise"
> 7000 Central Parkway, Suite 1700
> Atlanta, GA 30328
> Tel: 770.350.7998 / Fax: 770.350.9409
> http://www.aismedia.com / jchum at aismedia.com
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> -----Original Message-----
> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of Greg
> Freemyer
> Sent: Thursday, December 22, 2005 2:16 PM
> To: Atlanta Linux Enthusiasts
> Subject: Re: [ale] FGrep matches and non matches to two seperate files
>
> Are you just asking about "fgrep -v" ?
>
> On 12/22/05, Jonathan Chum <jchum at aismedia.com> wrote:
> >
> >
> >
> > I have a list of PostFix IDs in a file that I'm able to fgrep the initial
> > maillog and return all entries matching the IDs in the list. I'd like to
> > create two files with it though, one that contains the new maillog that
> > matches the IDs listed in the file and another file that contains the old
> > maillog without these lines.
> >
> >
> >
> > Any idea how I would go about accomplishing this? Thanks.
> >
> >
> >
> > Regards,
> >  Jonathan Chum
> >  Senior Developer
> >
> >
> >  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >  AIS Media, Inc. - "Passion. Innovation. Expertise"
> >  7000 Central Parkway, Suite 1700
> >  Atlanta, GA 30328
> >  Tel: 770.350.7998 / Fax: 770.350.9409
> >  http://www.aismedia.com / jchum at aismedia.com
> >  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
> >
> >
>
>
> --
> Greg Freemyer
> The Norcross Group
> Forensics for the 21st Century
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>


--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century



More information about the Ale mailing list