LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions
User Name
Password
Linux - Distributions This forum is for Distribution specific questions.
Red Hat, Slackware, Debian, Novell, LFS, Mandriva, Ubuntu, Fedora - the list goes on and on... Note: An (*) indicates there is no official participation from that distribution here at LQ.

Notices


Reply
  Search this Thread
Old 09-28-2010, 02:28 PM   #1
HuMan-BiEnG
Member
 
Registered: Jun 2010
Posts: 92

Rep: Reputation: 15
Question suing sed to remove certain list of strings from a file ???


Hello there,,

i want to know how can i use sed to remove a list of emails from my email list ?? please can anyone help me to do that ??

example :

- i have fileA & fileB
- fileA contain a list of emails (say 7 emails), while fileB contain 300 email (including the 7 emails in fileA)
- now i want to make fileB doesnt contain the list of emails in fileA (which are 7 emails)

any help will be appretiated ,,

may all accept my best regards,,

Last edited by HuMan-BiEnG; 09-28-2010 at 02:32 PM.
 
Old 09-28-2010, 03:21 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
You want to sue sed? What have they ever done to you?

But seriously, could you provide some actual examples of the text you want to remove? It's almost impossible to give clear advice when we have only vague descriptions to work with.

Finally, how do you know that sed would be the best tool for the job? It's usually better to simply explain what you want to accomplish, and leave the how to be determined in the discussion.
 
Old 09-29-2010, 10:32 AM   #3
HuMan-BiEnG
Member
 
Registered: Jun 2010
Posts: 92

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by David the H. View Post
You want to sue sed? What have they ever done to you?

But seriously, could you provide some actual examples of the text you want to remove? It's almost impossible to give clear advice when we have only vague descriptions to work with.

Finally, how do you know that sed would be the best tool for the job? It's usually better to simply explain what you want to accomplish, and leave the how to be determined in the discussion.
Hello David,

ictually you are write, about the tool of program that will help me to finish what i want ,,

the example you want :

FileA ,contain :
email1@domain.com
email4@domain.com
email6@domain.com

fileB ,contain :
email1@domain.com
email2@domain.com
email3@domain.com
email4@domain.com
email5@domain.com
email6@domain.com
email7@domain.com
email8@domain.com

now i want to remove emails in FileA from FileB, to make FileB contain :
email2@domain.com
email3@domain.com
email5@domain.com
email7@domain.com
email8@domain.com

thanks David for your concern ,,

accept my best regards,,
 
Old 09-29-2010, 11:02 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Hi HuMan-BiEnG,

Try this

Code:
diff fileA fileB | sed -n '/.com$/p' | sed 's/^> //'  > file
mv file fileB
Warm Regards,

Last edited by vinaytp; 09-29-2010 at 11:03 AM.
 
Old 09-29-2010, 07:24 PM   #5
kurumi
Member
 
Registered: Apr 2010
Posts: 228

Rep: Reputation: 53
Quote:
Originally Posted by HuMan-BiEnG View Post
Hello David,

ictually you are write, about the tool of program that will help me to finish what i want ,,

the example you want :

FileA ,contain :
email1@domain.com
email4@domain.com
email6@domain.com

fileB ,contain :
email1@domain.com
email2@domain.com
email3@domain.com
email4@domain.com
email5@domain.com
email6@domain.com
email7@domain.com
email8@domain.com

now i want to remove emails in FileA from FileB, to make FileB contain :
email2@domain.com
email3@domain.com
email5@domain.com
email7@domain.com
email8@domain.com

thanks David for your concern ,,

accept my best regards,,
go try these out
Code:
grep -f <file1> <file2>
grep -f <file2> <file1>
grep -v -f <file1> <file2>
grep -v -f <file2> <file1>
 
Old 09-30-2010, 02:11 AM   #6
HuMan-BiEnG
Member
 
Registered: Jun 2010
Posts: 92

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by vinaytp View Post
Hi HuMan-BiEnG,

Try this

Code:
diff fileA fileB | sed -n '/.com$/p' | sed 's/^> //'  > file
mv file fileB
Warm Regards,
Hello vinaytp,,

thank you man very alot

i really appretiate your kind helping so much

please man accept my best regards ,,

good luck vinaytp,,
 
Old 09-30-2010, 02:13 AM   #7
HuMan-BiEnG
Member
 
Registered: Jun 2010
Posts: 92

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by kurumi View Post
go try these out
Code:
grep -f <file1> <file2>
grep -f <file2> <file1>
grep -v -f <file1> <file2>
grep -v -f <file2> <file1>

Hello kurumi,,

thank you so much man for helping & offering me this solution ,,

please kurumi accept my regards,,

hope that all who helped me will be always & 4ever in a very good health

goodluck to everyone,,
 
Old 09-30-2010, 02:24 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by vinaytp View Post
Hi HuMan-BiEnG,

Try this

Code:
diff fileA fileB | sed -n '/.com$/p' | sed 's/^> //'  > file
mv file fileB
Warm Regards,
just doing a diff could mask all sorts of things. What if the addresses are not in the same order? why only .com suffix domains? why manually strip out the diff formatting instead of using proper formatting in the first place?
 
Old 09-30-2010, 02:44 AM   #9
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Code:
grep -f <file1> <file2>
grep -f <file2> <file1>
grep -v -f <file1> <file2>
grep -v -f <file2> <file1>
Works nice !!
 
Old 09-30-2010, 02:52 AM   #10
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Quote:
Originally Posted by acid_kewpie View Post
just doing a diff could mask all sorts of things. What if the addresses are not in the same order? why only .com suffix domains? why manually strip out the diff formatting instead of using proper formatting in the first place?
Hi,

I just tried to strip off the characters and lines other than required.

In the below output I needed to eliminate lines other than email address.
Also > character.
Code:
# diff fileA fileB
1a2,3
> email2@domain.com
> email3@domain.com
2a5
> email5@domain.com
3a7,8
> email7@domain.com
> email8@domain.com
I took .com into consideration since only .com set of email addresses were specified by the OP.

Warm Regards,
 
Old 10-11-2010, 02:52 AM   #11
gapan
Member
 
Registered: Feb 2007
Posts: 378

Rep: Reputation: 163Reputation: 163
Code:
for i in `cat fileA`; do sed -i "/^${i}$/d" fileB; done
 
Old 10-13-2010, 09:04 AM   #12
HuMan-BiEnG
Member
 
Registered: Jun 2010
Posts: 92

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by gapan View Post
Code:
for i in `cat fileA`; do sed -i "/^${i}$/d" fileB; done
Hello gapan,

many many thanks man ,& please accept my best regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to remove words in a file using sed or any other command Kilam orez Linux - Newbie 4 11-30-2009 08:52 AM
Get a list of delimited filenames from a text file (sed?) Ksearch Linux - Newbie 14 06-30-2009 04:51 PM
sed to remove specific lines in a file tekmann33 Linux - Newbie 3 05-21-2009 03:41 PM
Remove sections of a xml file with sed viniciusandre Linux - Software 2 04-20-2009 01:18 PM
using sed to remove line in a comma-delimited file seefor Programming 4 03-10-2009 03:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions

All times are GMT -5. The time now is 05:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration