unix - Compare two files with first column and remove duplicate row from 2nd file in shell script -


I will ask your questions with an example. I have two files:

File # 1

  002,948,998 752986QAK NTR974VTS 0000000 102,948,932 752986QSC NTR974VTS 0000000 102,948,933 752986QSC NTR974VTS 0000000  

File # 2 Desired output:

  002948998 752986QAK NTR974VTS 0000000 102948932 752986QSC NTR974VTS 0000000  

102948933 752986QSC NTR974VTS 0000000 002,901,998 752986KFK NTR974MTS 0,990,000

note :. There should no difference (in) between lines

I want to compare file 1 and file 2 using the first column and remove the entire line from file 2, if they match the first file Are there. I would like to save the result to 1 file or a new file, file # 3 which contains all the entries from file 1 file 2 (without duplicates with file 2). Please advise a good resolution in shell scripts.

I am currently using:

  awk 'FNR == nr {a [$ 1]; next};; ($ 1 in a) 'file1 file2 & gt; File 3 file3 & gt; & Gt;  

code> cat file1 file2 | Sort-U & gt; File 3

This will sort the output, which you can not be like that, but -u ( " sort exclusive") flag This will cause all duplicate lines to be removed.

If repetition is only the first column, you can add a specifier fields:

  cat file1 file2 | Sort-Y-K-1.1 & gt; File3  

If you have empty lines, how many ways can you get rid of them? grep through the whole thing pipe or if blank lines are spaces, then grep '[^]' , etc.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -