Shell Script to Create non-duplicate lists from two lists

File_A contains Strings:
a
b
c
d

File_B contains Strings:
a
c
z

Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below.

Resultant files:
File_New_A contains String:
a
c

File_New_B contains String:
z

Thank you in advance for your help.
mlv_99

Thanks for the reply danmero. I made a mistake in the description. Let me re-phrase the question again.

File_A contains Strings and content's elements are NOT IN ANY ORDER OR PATTERN AND file varies in size from one run to the next run:
a <- in both File_A and File_B
b <- unique to File_A
c <- in both File_A and File_B
d <- unique to File_A

File_B contains Strings and content's elements are NOT IN ANY ORDER OR PATTERN AND file varies in size from one run to the next run:
a <- in both File_A and File_B
c <- in both File_A and File_B
z <- unique to File_B

Need to have script written in either sh or ksh. Resultant files (File_New_A and File_New_B) is derived from comparing contents of files File_A and File_B where resultant string elements in File_New_A and File_New_B are listed below. Resultant File_New_A will contain only unique elements found only in File_A when compared with File_B. File_New_B will contain only unique elements found in only File_B when compared with File_A.

Resultant files:
File_New_A contains String:
b <- unique to File_A
d <- unique to File_A

File_New_B contains String:
z <- unique to File_B

++++++++++++++++++++++++++++++++++++++

The next run could have

File_A contains Strings and content's elements are NOT IN ANY ORDER OR PATTERN AND file varies in size from one run to the next run:
m <- only in File_A
n <- only in File_A
o <- only in File_A
p <- only in File_A
q <- in both File_A and File_B
r <- in both File_A and File_B

File_B contains Strings and content's elements are NOT IN ANY ORDER OR PATTERN AND file varies in size from one run to the next run:
q <- in both File_A and File_B
r <- in both File_A and File_B

Resultant files after comparing File_A and File_B:

Resultant files:
File_New_A contains String:
m <- unique to File_A
n <- unique to File_A
o <- unique to File_A
p <- unique to File_A

File_New_B contains String:

No elements in File_New_B since File_B have no unique elements to File_B, all files in File_B are also in File_A; therefore File_New_B is empty.

I hope this is more clearer.

Thank you.

Matt

awk 'NR==FNR{arr[$0];next}$0 in arr{next}1' File_A File_B

You can change the input file order to get the opposite.

You guys are awesome! Masters of the one-liners! Works perfectly! Thanks so much for your help. :slight_smile:
Matt

Now is clear :wink:

grep -vf File_B File_A > File_New_A
grep -vf File_A File_B > File_New_B

:slight_smile: Thanks Danmero! Exactly what I was looking for!
-Matt

Hi,

I have a question. My post was not published, I have no idea why. But, it is a good.:slight_smile:
The command "comm" is not suitable for this? If not, why?

Greeting

Yes it is, however your reply is not acceptable for this forum, aka man comm, read the manual, RTM, etc

Next time try to provide a solution or try to explain the solution:

comm -23 File_A File_B > File_New_A

comm -13 File_A File_B > File_New_B

, quote from man and after that suggest the user to read the manual , even provide a link to man comm

Welcome to unix.com forum, take your time and you'll find your way around.