是否有与UNIX相同的UNIX命令
sort | uniq
Run Code Online (Sandbox Code Playgroud)
找到字符串集交叉点或"异常值".
一个示例应用程序:我有一个html模板列表,其中一些有{%load i18n%}字符串在里面,有些则没有.我想知道哪些文件没有.
编辑: grep -L解决了上述问题.
这个怎么样:
文件1:
mom
dad
bob
Run Code Online (Sandbox Code Playgroud)
文件2:
dad
Run Code Online (Sandbox Code Playgroud)
%与file1 file2相交
dad
Run Code Online (Sandbox Code Playgroud)
%left-unique file1 file2
mom
bob
Run Code Online (Sandbox Code Playgroud)
Dal*_*und 37
它似乎grep -L解决了海报的真正问题,但对于实际问题,找到两组字符串的交集,你可能想查看"comm"命令.例如,if file1和file2each包含一个排序的单词列表,每行一个单词
$ comm -12 file1 file2
Run Code Online (Sandbox Code Playgroud)
将生成两个文件共有的单词.更一般地说,给定排序的输入文件file1和file2命令
$ comm file1 file2
Run Code Online (Sandbox Code Playgroud)
产生三列输出
您可以N使用-N选项禁止输出中的列.因此,上面的命令会comm -12 file1 file2抑制第1列和第2列,只留下两个文件共有的字.
相交:
# sort file1 file2 | uniq -d
dad
Run Code Online (Sandbox Code Playgroud)
左边唯一:
# sort file1 file2 | uniq -u
bob
mom
Run Code Online (Sandbox Code Playgroud)
从http://www.commandlinefu.com/commands/view/5710/intersection-between-two-files:
两个(未排序)文件之间的交集:
grep -Fx -f file1 file2
Run Code Online (Sandbox Code Playgroud)
file2中不在file1中的行:
grep -Fxv -f file1 file2
Run Code Online (Sandbox Code Playgroud)
说明:
-f选项告诉grep读取要从文件中查找的模式。这意味着它将对file1中的每一行执行file2搜索。-F选项告诉grep将搜索字词视为固定字符串,而不是模式,因此a.c只会匹配a.c而不是abc,-x选项告诉grep进行整行搜索,以便file1中的“ foo”与file2中的“ foobar”不匹配。-v选项告诉grep仅显示不匹配的行,从而为file2提供唯一的行。也许我误解了这个问题,但为什么不只是使用grep来查找字符串(使用-L选项让它打印出没有字符串的文件的名称).
换一种说法
grep -L "{% load i18n %}" file1 file2 file3 ... etc
Run Code Online (Sandbox Code Playgroud)
或者使用通配符作为文件名.