The ability to retrieve a list of today's saved files in a directory that stores an archive and
Use the diff command to compare the list of recent saved files to the list of today's saved files and
I would like to create a shell that extracts differences that existed the other day and do not exist today.
However, if you use the diff command to extract the difference, you will extract the difference between both files.
I couldn't find any diff options.
How can I create a diff command that ignores the presence or absence of A and displays the difference between B and A?
shell
There is a command to classify two sorted files, the comm command, into lines that exist only in each file and lines that are common.(If you're not particular about using the diff command...)
The comm command must give a file with the lines sorted.(From the text of the question, it seems like a file that can be sorted, but you need to check if it is.)
First, use the following command:
for parts that exist only in A.txt, parts that exist only in B.txt, and parts that are common.
I can separate them, so please check them out.
comm<(sort A.txt)<(sort B.txt)
You can specify options to print only the three parts that you want.A. Specify --23 を to output only parts that exist in txt.
comm-23<(sort A.txt)<(sort B.txt)
Difference
that existed the other day (B) and does not exist today (A)
「I didn't know what the condition of "ignore the presence or absence of A" meant.
List of recent days B.txt
d
c
B
a
Today's List A.txt
a
c
e
In , b
and d
no longer exist, and e
appears new.
Do you mean you want to extract b
and d
at this time?
If so,
diff<(sort A.txt)<(sort B.txt)
1a2
>b
3c4
<e
---
>d
of
You can extract lines that begin with >
.
[Procedure]
diff<(sort A.txt)<(sort B.txt)|grep'^>'|sed's/^>//'
[Results]
b
d
[Environment of execution]
GNU bash, version 4.4.20(1)-release(x86_64-pc-linux-gnu)
diff(GNU diffutils) 3.6
grep(GNU grep) 3.1
sed(GNUsed) 4.4
sort (GNU coreutils) 8.28
© 2024 OneMinuteCode. All rights reserved.