[PLUG] natural join on text files

Russell Senior seniorr at aracnet.com
Fri Mar 7 15:36:01 UTC 2003


>>>>> "Russell" == Russell Senior <seniorr at aracnet.com> writes:

>>>>> "Alice" == Alice Corbin <ali at axian.com> writes:

Alice> grep -f file1 file2

Russell> [...] I could send file1 through some "armoring" filter, with
Russell> a "^" and the front and a delimiter at the end and pipe it
Russell> like:

Russell>   $ <filter> file1 | grep -f - file2

And, here is what seems to be a suitable filter and command-line:

  $ sed 's/^\(.*\)[ ]*$/^\1($| )/' file1 | egrep -f - file2

I'll stipulate that I don't care about whitespace at the end of line
in file1, since it is mostly invisible and caring about it seems more
likely to cause confusion.  

In order to match lines that begin with my key and then either end or
have a delimiter followed by other data, I need (?) an optional, such
as ($| ) in egrep syntax.

Comments?

-- 
Russell Senior         ``I've seen every kind of critter God ever made,
seniorr at aracnet.com      and I ain't never seen a meaner, lower, more
                         stinkin' yellow hypocrite than you!'' 
                                        -- Burl Ives as Rufus Hennessy




More information about the PLUG mailing list