For example, generally I need to check for 5 strings. (Note : the strings are in file format .txt)

  1. file1.txt
  2. file2.txt
  3. file3.txt
  4. file4.txt
  5. file5.txt

but there are 3 strings in abc.txt

  1. file1.txt
  2. file2.txt
  3. file3.txt

I wanted to check for specific strings in that abc.txt file and write the missing strings to xyz.txt file using a shell script.

example :-

  1. file1.txt, file2.txt, file3.txt already exists in abc.txt --> so, it should leave or print any message like mentioned string exists

  2. file4.txt, file5.txt does not exists in abc.txt --> so, when I check for these 2 strings, it should print a message specified file does not exits and it should write that missing string to xyz.txt file

example:- Input:- file/script/abc.txt abc.txt contains the following file1.txt file2.txt file3.txt

output:- file/script/xyz.txt xyz.txt should contain the following file4.txt file5.txt

Please note:- file4 and file5 are missing files in abc.txt

I have used the below code:-

Could anyone please help me as soon as possible.

Thanks in advance

  • Please edit your question, and add an example input and expected output. What is in these files? Also, you have tagged with bash and ksh, two very different shells and also with putty. Please edit and tell us what operating system you are using and what shell.
    – terdon
    Jul 8, 2022 at 8:41

1 Answer 1


$ comm -23 <(sort -u file1.txt) <(sort -u file2.txt) > linesUniqueToFile1.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .