How to sort and compare files in more efficient manner?

Hello All,

Iam using below method to sort and compare files. First iam doing sorting and changing the same file and then doing comparing and taking the final result to another file.

sort -o temp.txt file1
mv temp.txt file1
sort -o temp.txt file2
mv temp.txt file2
sort -o temp.txt file3
mv temp.txt file3
comm -23 file1 file2 > file4
comm -23 file4 file3 > file5
awk -v RS='' -v OFS="," '$1=$1'  file5 > file6
mv file6  file5

Is their a more better or clear way of doing the above task.

If you are using a recent shell, you can try process substitution:

$ comm -23 <(sort file1) <(sort file2) > file4
$ comm -23 file4 <(sort file3) | awk .... > file5

For further refinement, I'd need some input and desired output data.

Hi Rudic,

Thanks for the response but somehow iam getting below error. Not sure iam trying it correctly or not.

 comm -23  <(sort /apps/psr/build_dev/Modified_workflow_env52ws.lst) <(sort /apps/psr/build_dev/bpel_new_version_env52ws.lst) > /apps/psr/build_dev/diff_workflows.lst
 
-sh: syntax error near unexpected token `('
 

What OS and shell are you using?

Iam using bourne shell and Linux (Redhat 5).

OK, the bourne shell may not come with process substitution. Do you have bash or ksh available?

Yes Rudic bash and ksh both are available. So shall i try in bash.

Yup it worked in Bash. Thank you.