remove matching partial lines from two files ...

remove matching partial lines from two files ...

Post by daraburk.. » Mon, 20 Feb 2006 15:59:49



So I have one file of email addresses and another of bogey domain
names. I want to completely earse any lines in my email address file -
that correspond to a bogey domain name...

MAIN_FILE:




BOGEY_FILE:
heraddress
ouraddress

.... bash script here  & result =...

MAIN_FILE:


Can anyone help ? ... thanks in advance :-)

 
 
 

remove matching partial lines from two files ...

Post by Chris F.A. Johnso » Mon, 20 Feb 2006 22:47:15



> So I have one file of email addresses and another of bogey domain
> names. I want to completely earse any lines in my email address file -
> that correspond to a bogey domain name...

> MAIN_FILE:




> BOGEY_FILE:
> heraddress
> ouraddress

> .... bash script here  & result =...

> MAIN_FILE:


> Can anyone help ? ... thanks in advance :-)

grep -v -f BOGEY_FILE MAIN_FILE > NEW_MAIN_FILE &&
mv NEW_MAIN_FILE MAIN_FILE

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence

 
 
 

remove matching partial lines from two files ...

Post by William Jame » Tue, 21 Feb 2006 07:57:04



> So I have one file of email addresses and another of bogey domain
> names. I want to completely earse any lines in my email address file -
> that correspond to a bogey domain name...

> MAIN_FILE:




> BOGEY_FILE:
> heraddress
> ouraddress

> .... bash script here  & result =...

> MAIN_FILE:


> Can anyone help ? ... thanks in advance :-)

This will perform an in-place edit of MAIN_FILE:

ruby -e 'BEGIN{A=gets(nil).to_a;$-i=""};puts gets(nil).to_a-A'
BOGEY_FILE MAIN_FILE

 
 
 

remove matching partial lines from two files ...

Post by grulo » Tue, 21 Feb 2006 12:32:01



> So I have one file of email addresses and another of bogey domain
> names. I want to completely earse any lines in my email address file -
> that correspond to a bogey domain name...

> MAIN_FILE:




> BOGEY_FILE:
> heraddress
> ouraddress

> .... bash script here  & result =...

> MAIN_FILE:


> Can anyone help ? ... thanks in advance :-)

#!/bin/bash
while read main; do

   host=${host%%.*}
   while read bogey; do
      [ "$host" == "$bogey" ] && break
   done<BOGEY_FILE ||echo "$main"
done<MAIN_FILE

or if you have bash v3+

#!/bin/bash
while read main; do
   while read bogey; do

      [ "${BASH_REMATCH[1]}" == "$bogey" ] &&
      break
   done<BOGEY_FILE || echo "$main"
done<MAIN_FILE

--
http://grulos.blogspot.com/

 
 
 

remove matching partial lines from two files ...

Post by Ed Morto » Tue, 21 Feb 2006 22:48:32




>>So I have one file of email addresses and another of bogey domain
>>names. I want to completely earse any lines in my email address file -
>>that correspond to a bogey domain name...

>>MAIN_FILE:




>>BOGEY_FILE:
>>heraddress
>>ouraddress

>>.... bash script here  & result =...

>>MAIN_FILE:


>>Can anyone help ? ... thanks in advance :-)

> grep -v -f BOGEY_FILE MAIN_FILE > NEW_MAIN_FILE &&
> mv NEW_MAIN_FILE MAIN_FILE

If BOGEY_FILE contained "tom" as a bad address, in addition to removing


Here's how to do it in awk:


Obviously, there's no way to distinguish ".com"s from ".net"s etc. in
the above.

Regards,

        Ed.

 
 
 

remove matching partial lines from two files ...

Post by daraburk.. » Wed, 22 Feb 2006 01:49:23


wow, thanks guys ... :-)