veh*_*zzz 77 bash scripting awk sed file
我有两个文件:
档案1
dsf
sdfsd
dsfsdf
Run Code Online (Sandbox Code Playgroud)
档案2
ljljlj
lkklk
dsf
sdfsd
dsfsdf
Run Code Online (Sandbox Code Playgroud)
我想显示文件2中的内容,但不显示文件1中的内容,因此文件3应该如下所示
ljljlj
lkklk
Run Code Online (Sandbox Code Playgroud)
dog*_*ane 139
grep -Fxvf file1 file2
Run Code Online (Sandbox Code Playgroud)
标志意味着什么:
-F, --fixed-strings
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.
Run Code Online (Sandbox Code Playgroud)
kri*_*ico 51
你可以试试
grep -f file1 file2
Run Code Online (Sandbox Code Playgroud)
要么
grep -v -F -x -f file1 file2
Run Code Online (Sandbox Code Playgroud)
dog*_*ane 39
您可以使用该comm命令比较两个已排序的文件
comm -13 <(sort file1) <(sort file2)
Run Code Online (Sandbox Code Playgroud)
Luc*_*one 12
我成功使用了
diff "${file1}" "${file2}" | grep "<" | sed 's/^<//g' > "${diff_file}"
Run Code Online (Sandbox Code Playgroud)
将差异输出到文件.