我有两个大文件(文件名集).每个文件大约有30,000行.我试图找到一种快速查找file1中不存在于file2中的行的方法.
例如,如果这是file1:
line1
line2
line3
Run Code Online (Sandbox Code Playgroud)
这是file2:
line1
line4
line5
Run Code Online (Sandbox Code Playgroud)
然后我的结果/输出应该是:
line2
line3
Run Code Online (Sandbox Code Playgroud)
这有效:
grep -v -f file2 file1
但是在我的大文件上使用它时非常非常慢.
我怀疑有一个很好的方法来使用diff(),但输出应该只是行,没有别的,我似乎无法找到一个开关.
任何人都可以帮我找到一个快速的方法,使用bash和基本的Linux二进制文件?
编辑:为了跟进我自己的问题,这是我到目前为止使用diff()找到的最好方法:
diff file2 file1 | grep '^>' | sed 's/^>\ //'
Run Code Online (Sandbox Code Playgroud)
当然,必须有更好的方法吗?
我有一个文件f1:
line1
line2
line3
line4
..
..
Run Code Online (Sandbox Code Playgroud)
我想删除另一个文件中的所有行f2:
line2
line8
..
..
Run Code Online (Sandbox Code Playgroud)
我想的东西cat和sed,这甚至还没有接近我所预期的.我怎样才能做到这一点?
我有两个文件(比如说a.txt和b.txt),两个文件都有一个名字列表.我已经sort在这两个文件上运行了.
现在我想找到a.txt不存在的行b.txt.
(我花了很多时间来找到这个问题的答案,所以记录下来以备将来参考)
我有两个文件:
档案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) 我希望打印一个文件中但不在另一个文件中的行.但是,这两个文件都没有排序,我需要在两个文件中保留原始顺序.
contents of file1:
string2
string1
string3
contents of file2:
string3
string1
Output:
string2
Run Code Online (Sandbox Code Playgroud)
有一个简单的脚本,我可以完成这个吗?
我有一个巨大的git repo,最终想用bfg清理.
但首先,我想跟踪并删除HEAD哪个git视为二进制文件...
所以,我正在寻找的是一个命令来查找HEAD中git视为二进制文件的所有文件.
这些没有帮助:
预先感谢您的帮助.
想象一下文件1:
#include "first.h"
#include "second.h"
#include "third.h"
// more code here
...
Run Code Online (Sandbox Code Playgroud)
想象一下文件2:
#include "fifth.h"
#include "second.h"
#include "eigth.h"
// more code here
...
Run Code Online (Sandbox Code Playgroud)
我想获取文件2中包含的标题,但不是文件1中的标题,只是那些行.因此,当运行时,文件1和文件2的差异将产生:
#include "fifth.h"
#include "eigth.h"
Run Code Online (Sandbox Code Playgroud)
我知道如何在Perl/Python/Ruby中实现它,但我想在不使用不同编程语言的情况下完成此任务.
git ls-files
Run Code Online (Sandbox Code Playgroud)
还列出了子模块。
使用:列出 git 存储库中的子模块以及如何从另一个文件 A 中删除出现在文件 B 上的行?我可以:
git ls-files | grep -Fxvf <(git submodule status | cut -d' ' -f3)
Run Code Online (Sandbox Code Playgroud)
或更详细和通用的:
git ls-files | while IFS='' read -r file; do
if [ -f "$file" ]; then
echo "$file"
fi
done
Run Code Online (Sandbox Code Playgroud)
使用一些 git 命令/标志有更短的方法吗?
我每天都会收到一个文件,其中有 10,000 条记录,其中 99% 都在最后一天的文件中。如何使用 macOS 命令行删除新文件中前一天文件中存在的行?
remove_duplicates newfile oldfile
Run Code Online (Sandbox Code Playgroud)
这些文件看起来像这样:
"First Last"\t"email"\t"phone"\t"9 more columns..."
Run Code Online (Sandbox Code Playgroud)
注意,我尝试了这个awk解决方案,但它没有输出任何内容,即使我确认了重复的行。