ysf / anewer

anewer appends lines from stdin to a file if they don't already exist in the file. This is a rust version of https://github.com/tomnomnom/anew
https://github.com/ysf/anewer
GNU General Public License v3.0
57 stars 4 forks source link

Invert #1

Closed jaikishantulswani closed 3 years ago

jaikishantulswani commented 3 years ago

@ysf It would be good if it have invert match functionality too which is not in anew.

ysf commented 3 years ago

Do you have an example on what you'd like to invert? Thank you!

jaikishantulswani commented 3 years ago

@ysf suppose you sometimes need to append only the new list of contents to the file but sometime you also want to get the list of contents which are not matched like grep -vf

kpcyrd commented 3 years ago

@jaikishantulswani can you show some examples how it's supposed to behave? If I understood you right you're looking for something like this:

$ cat foo1.txt
a
b
c
$ anewer --invert foo1.txt # no output because no duplicates
$ cat foo2.txt
a
b
c
c
$ anewer --invert foo2.txt # the c line is in there twice, so we print the duplicate line
c
$ cat foo3.txt
a
b
b
c
c
c
$ anewer --invert foo3.txt # if the line is duplicated multiple times we're also going to show it multiple times
b
c
c
jaikishantulswani commented 3 years ago

@ysf I would like to get a feature like grep -vf, like the below example :

# cat foo1.txt 
a
b
c
d
# cat foo2.txt 
a
b
c
d
e
f
# cat foo2.txt | grep -vf foo1.txt 
e
f
ysf commented 3 years ago

@ysf I would like to get a feature like grep -vf, like the below example :

# cat foo1.txt 
a
b
c
d
# cat foo2.txt 
a
b
c
d
e
f
# cat foo2.txt | grep -vf foo1.txt 
e
f

But this is exactly what anewer does already:

cat foo2.txt | anewer foo1.txt e f

Are you sure you don't mean it the way kpcyrd says?

ysf commented 3 years ago

Either way, I just added an invert parameter like grep has it :)