0

I'm using BASH to compare two files, but I only want to receive an output if there is a line in the first file that isn't in the second. I only want to see the < results. How can I do this?

I've tried:

diff /"ripe_route_from_"$place"_v4" /"unspecified_route_from_"$place"_v4" | egrep '<|>' > "diff_ripe_unspecified"_$place

egrep '<' "diff_ripe_unspecified"_$place > ripe_routes_diff_unspecified

(file locations censored, that's not part of the issue)

but it doesn't give me a result.

Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31
Navar0ne
  • 1
  • 3
  • 1
    https://stackoverflow.com/questions/15384818/how-to-get-the-difference-only-additions-between-two-files-in-linux https://stackoverflow.com/a/15385080/9072753 – KamilCuk Jul 04 '23 at 09:34
  • With GNU diff: `diff --unchanged-line-format= --new-line-format= --old-line-format='< %L' oldfile newfile` – jhnc Jul 04 '23 at 11:26

1 Answers1

1

I suggest that your problem lies elsewhere. In a simplified version:

$ cat a          
a
a
a
a
$ cat b
a
a
b
$ diff a b
3,4c3
< a
< a
---
> b
$ diff a b | grep -E '<|>'
< a
< a
> b
$ diff a b | grep -E '<|>' | grep -E '<'
< a
< a

(note: I've used grep -E which for this is functionally the same, because egrep is deprecated since 2007)

Ljm Dullaart
  • 4,273
  • 2
  • 14
  • 31
  • `egrep` has been deprecated in favor of `grep -E` for about 20 years and that would find lines that contain `<` or `>` anywhere. – Ed Morton Jul 04 '23 at 11:22
  • 1
    I tried to follow the OP's use. But I've changed it and added a note. – Ljm Dullaart Jul 04 '23 at 11:34
  • If you change `grep -E '<|>'` to `grep -E '^(<|>)'` or just `grep '^[<>]'` (and `grep -E '<'` to `grep '^<'`) then it'll solve the other problem of matching `<` or `>` anywhere in the output. – Ed Morton Jul 04 '23 at 11:36
  • 1
    Yes, but the OP complains that there is no result. Not a wrong result, no result. Clearly, something else is wrong. Using `diff .... | grep '^<'` would even eliminate the intermediate file. – Ljm Dullaart Jul 04 '23 at 11:49