简体   繁体   English

比较Linux中2个文件的不同单词

[英]Comparing 2 files in linux for different word

I have two files like below 我有两个像下面的文件

file1 has the below words file1具有以下字词

word23.cs
test.cs
only12.cs

file 2 has the below words 文件2包含以下字词

word231.cs
test.cs
only12.cs 

The above words might change, And now i need to compare the two files using script or linux command to get the different word , i need to compare the file2 with file1 and need to get the output as word23.cs 上面的单词可能会更改,现在我需要使用脚本或linux命令比较两个文件以获取不同的单词,我需要将file2与file1比较,并需要将输出作为word23.cs

Thank you 谢谢

You can use comm , diff or cmp command to find different word from files. 您可以使用commdiffcmp命令从文件中查找其他单词。

Also this trick can work with a grep command as follows 同样,此技巧可以与grep命令配合使用,如下所示

grep -Fwf file1 file2

Use the "diff" command to compare 2 files: 使用“ diff”命令比较2个文件:

$ diff a.txt b.txt

Or, for a unified diff: 或者,对于统一的差异:

$ diff -u a.txt b.txt

Use -u0 for a unified diff without context. -u0用于不带上下文的统一差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM