LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Remove all the matched lines from second file (https://www.linuxquestions.org/questions/linux-newbie-8/remove-all-the-matched-lines-from-second-file-4175512475/)

Almaz 07-28-2014 02:23 AM

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

Almaz 07-28-2014 02:38 AM

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)

grail 07-28-2014 08:35 AM

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

Almaz 07-28-2014 01:52 PM

Quote:

Originally Posted by grail (Post 5210752)
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.


All times are GMT -5. The time now is 03:21 AM.