LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-28-2014, 03:23 AM   #1
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Rep: Reputation: Disabled
Remove all the matched lines from second file


I have 2 hosts file. I need to remove from first file all the lines which matches second file.

Example
File1

127.0.0.1 swaypix.com
127.0.0.1 www.swaypix.com
127.0.0.1 redtram.com
127.0.0.1 goods.redtram.com

File2
swaypix.com
www.swaypix.com
buyshoesfitflop.webs.com

Output:
127.0.0.1 redtram.com
127.0.0.1 goods.redtram.com

What's the best way to do that? Thank you in advance

Last edited by Almaz; 07-28-2014 at 03:39 AM.
 
Old 07-28-2014, 03:38 AM   #2
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
Problem Solved:

Answer to my own question

I had to delete all "127.0.0.1" from File1

join -v 1 <(sort fileA) <(sort fileB)

Last edited by Almaz; 07-28-2014 at 03:48 AM.
 
Old 07-28-2014, 09:35 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I am curious how your solution has provided you with your output?

Surely if you have gone to the trouble of editing File1, running your commands and then opening the outputed file to once again re-add the ip addresses, it would
have been quicker to have just manually created the file in the first place?

Maybe you could have tried something like:
Code:
grep -vf File2 File1
 
Old 07-28-2014, 02:52 PM   #4
Almaz
Member
 
Registered: Jul 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
I am curious how your solution has provided you with your output?

Surely if you have gone to the trouble of editing File1, running your commands and then opening the outputed file to once again re-add the ip addresses, it would
have been quicker to have just manually created the file in the first place?

Maybe you could have tried something like:
Code:
grep -vf File2 File1
Thanks I like your method even better.
 
  


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
[SOLVED] A RegEx question. cab00t Linux - Newbie 12 07-21-2014 06:05 AM
regex question dnoy Linux - General 2 12-07-2012 12:54 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 02:10 AM
A question about regex trist007 Linux - Newbie 12 09-16-2010 02:20 PM
regex question Toadman Linux - General 0 12-30-2005 01:59 PM


All times are GMT -5. The time now is 10:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration