[英]is it possible to get the content of file1 minus file2 by using bash cmd?
I have two files:我有两个文件:
log.txt
log.bak2022.06.20.10.00.txt
the log.bak2022.06.20.10.00.txt
is the backup of log.txt
at 2022.06.20 10:00
. log.bak2022.06.20.10.00.txt
是log.txt
在2022.06.20 10:00
的备份。
but the log.txt
is a content-increasing file.但
log.txt
是一个增加内容的文件。
now I have a requirement, I want get the content of log.txt
minus log.bak2022.06.20.10.00.txt
, then write into a new file.现在我有一个要求,我想得到
log.txt
减去log.bak2022.06.20.10.00.txt
的内容,然后写入一个新文件。 is it possible to implement it?有可能实施吗?
Assumptions:假设:
Sample inputs:样本输入:
$ cat small
4
2
1
3
$ cat big
4
2
1
3
8
10
9
4
One comm
idea:一个
comm
的想法:
$ comm --nocheck-order -13 small big
8
10
9
4
One awk
idea:一个
awk
的想法:
$ awk '
FNR==NR { max=FNR; next }
FNR>max
' small big
8
10
9
4
One wc/sed
idea:一个
wc/sed
的想法:
$ max=$(wc -l < small)
$ ((max++))
$ sed -n "$max,$ p" big
8
10
9
4
awk
-based solution without need for unix piping |
基于
awk
的解决方案,无需 unix |
chains, regex
, function calling, or array
splitting :链、
regex
、函数调用或array
拆分:
{m,n,g}awk '(_+= NR==FNR ) < FNR' FS='^$' small.txt big.txt
8
10
9
4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.