Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use awk sed command and while loop to remove entries from second file

I have two output files:

  1. FILE-A contains 70,000+ unique entries.
  2. FILE-B contains a unique listing that I need to remove from FILE-B.

FILE-A:

 TOM
 JACK
 AILEY
 BORG
 ROSE
 ELI

FILE-B Content:

 TOM
 ELI

I want to remove anything listed in FILE-B from File-A.

FILE-C (Result file):

 JACK
 AILEY
 BORG
 ROSE

I assume I need a while r for i statement. Can someone help me with this? I need to cat and read FILE-A and for every line in FILE-B I need to remove that from FILE-A.

What command should I use?

like image 466
theuniverseisflat Avatar asked Jul 17 '26 07:07

theuniverseisflat


2 Answers

You don't need either awk, sed, or a loop. You just need grep:

fgrep -vxf FILE-B FILE-A

Please note the use of -x to match entries exactly.

Output:

JACK
AILEY
BORG
ROSE
like image 126
lcd047 Avatar answered Jul 18 '26 20:07

lcd047


You can use grep -v -f:

grep -xFvf FILE-B FILE-A
ACK
AILEY
BORG
ROSE
like image 39
anubhava Avatar answered Jul 18 '26 22:07

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!