我有一个大约一百万行的文件,如下所示:
"ID" "1" "2"
"00000687" 0 1
"00000421" 1 0
"00000421" 1 0
"00000421" 1 0
Run Code Online (Sandbox Code Playgroud)
最后一行重复了超过一百万次。从这个问题中获得灵感,我尝试了一些建议的解决方案,看看哪个更快。我原以为只有一个进程的解决方案会比那些有管道的解决方案更快,因为它们只使用一个进程。但这些是我的测试结果:
tail -n +2 file.txt | tr -d \"
$ time tail -n +2 file.txt | tr -d \" 1> /dev/null
real 0m0,032s
user 0m0,020s
sys 0m0,028s
Run Code Online (Sandbox Code Playgroud)sed '1d;s/"//g' file.txt
$ time sed '1d;s/"//g' file.txt 1> /dev/null
real 0m0,410s
user 0m0,399s
sys 0m0,011s
Run Code Online (Sandbox Code Playgroud)perl -ne ' { s/"//g; print if $. > 1 }' file.txt
$ time perl -ne ' { s/"//g; …
Run Code Online (Sandbox Code Playgroud)在一个练习的解决方案中,我发现了这一点:
nc -z [serverip] [port]
Run Code Online (Sandbox Code Playgroud)
它有什么作用?
在nc
手册页上我发现
-z 零 I/O 模式 [用于扫描]
不是很解释......在网上搜索我找到了Netcat Cheat Sheet,上面写着:
-z:零 I/O 模式(不发送任何数据,只发出一个没有负载的数据包)
那么,为什么我要发送一个没有任何内容的数据包?这就像一个ping?
我正在尝试编写一个脚本,当静态网页发生更改时会通知我。为此,我使用wget
下载网页,并diff
检查它是否已更改。我正在运行 Ubuntu 20.04 LTS 虚拟机。这是示例:
$ wget --quiet https://twiki.di.uniroma1.it/twiki/view/Reti_Avanzate/InternetOfThings2021 -O file1
$ wget --quiet https://twiki.di.uniroma1.it/twiki/view/Reti_Avanzate/InternetOfThings2021 -O file2
$ diff -q file1 file2
Files file1 and file2 differ
Run Code Online (Sandbox Code Playgroud)
如您所见,diff
报告两个文件之间的差异。为什么?即使我试图将它们与diff -y
它们对我来说看起来一样。
更新
寻找差异与git diff --color-words -- file1 file2
给出以下结果:
显然,有一个字段添加了时间戳,在两个文件之一中,另一个文件<!--GENERATED_HEADERS-->
中没有。
关于如何解决它的任何想法?