original! linux comm command file comparison output intersection, set difference.

File along the following lines:

112805 | 300011222483 | OL sea 12 Zhuo | 47397c33e36cdbed26637c50dd305973 | 2019-08-06 10: 50: 13 | Gordon B record 123 | succ |
221 805 | 3,002,228,346 | 12 Carsafe S Zhuo | ce125ad05675ac2c73de325d4d573707 | 2019-08-06 10:49: 20 | A code parity number (SDK) 123 | succ |

........

 

 

Question: if a single file line coming from third-party billing document has been 1, but due to a fault, incomplete content file 1, file back to the full amount of 2, 2 it is to exclude files with the file contents of a total of 1 line, which excludes 1 file has been charging all the contents of the line.

Existing file: 1.txt 2.txt, now get only some of the content in line 2.txt.

Use comm command

comm -3 file1 file2
This approach looks easiest. Comm command function is progressive compare two sorted files, there are three default output: only some lines in file1, file2 only some lines in, the file1 and file2 common to the line.

There -1-2-3 parameters respectively corresponding to suppress the output column. For example, in our approach II, the practical -3 parameters, and file1 file2 not common to the output section. That we can achieve the purpose of this article.

 

So the first sort:

sort 1.txt -o 1_sort.txt

sort 2.txt -o 2_sort.txt

Comm reuse file2 command output only in some rows (set difference):

comm -1 -3 1_sort.txt  2_sort.txt > only_2_have_sort.txt

 

Guess you like

Origin www.cnblogs.com/wuyun-blog/p/11416908.html