Skip to main content
Tweeted twitter.com/StackUnix/status/1016282840139534338
added 5 characters in body
Source Link
slm
  • 379.7k
  • 127
  • 793
  • 897

I'm tringtrying to do simple grep and grep -v so I will get the lines from a.txt that exists onin b.txt and not in c.txt.

Example of 3 files

Example of 3 files

a.txt:

a
b
c
d
e

up.txt:

a.up
b.up
c.up

dw.txt:

a.dw
b.dw

Desired output:

c

I wrote the below code but the grep looks on the $(sed...) as one single line at a time and not as a whole:

sed 's/.up//' /tmp/b.txt | grep -f /tmp/a.txt | grep -vf $(sed 's/.dw//' /tmp/c.txt)

I'm tring to do simple grep and grep -v so I will get the lines from a.txt that exists on b.txt and not in c.txt.

Example of 3 files

a.txt:

a
b
c
d
e

up.txt:

a.up
b.up
c.up

dw.txt:

a.dw
b.dw

Desired output:

c

I wrote the below code but the grep looks on the $(sed...) as one single line at a time and not as a whole:

sed 's/.up//' /tmp/b.txt | grep -f /tmp/a.txt | grep -vf $(sed 's/.dw//' /tmp/c.txt)

I'm trying to do simple grep and grep -v so I will get the lines from a.txt that exists in b.txt and not in c.txt.

Example of 3 files

a.txt:

a
b
c
d
e

up.txt:

a.up
b.up
c.up

dw.txt:

a.dw
b.dw

Desired output:

c

I wrote the below code but the grep looks on the $(sed...) as one single line at a time and not as a whole:

sed 's/.up//' /tmp/b.txt | grep -f /tmp/a.txt | grep -vf $(sed 's/.dw//' /tmp/c.txt)
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
Source Link
Nir
  • 1.4k
  • 7
  • 25
  • 36

grep lines that exists on one file but not in the other

I'm tring to do simple grep and grep -v so I will get the lines from a.txt that exists on b.txt and not in c.txt.

Example of 3 files

a.txt:

a
b
c
d
e

up.txt:

a.up
b.up
c.up

dw.txt:

a.dw
b.dw

Desired output:

c

I wrote the below code but the grep looks on the $(sed...) as one single line at a time and not as a whole:

sed 's/.up//' /tmp/b.txt | grep -f /tmp/a.txt | grep -vf $(sed 's/.dw//' /tmp/c.txt)