[Techtalk] finding added lines in a file

Miriam English mim at miriam-english.org
Thu Aug 15 23:59:24 UTC 2013


Hi folks,

Forgive my thickness. I've read (or attempted to read) the manual pages 
for diff, cmp, and comp and still can't work out how to list just the 
lines added to file B when comparing two files, A and B. Perhaps I can 
blame having just getting out of hospital after a bout with a mystery 
high fever, but I do remember having difficulty trying to work this out 
before too.

Anybody know the secret?

  - compare two files, A and B
  - just print the additional lines of file B

It should be easy, right? I'm completely stumped.

I have used the two-step
  cat A.txt B.txt | sort | uniq -u >C.txt
  cat C.txt B.txt | sort | uniq -d
but this uses a temporary file (C.txt) and upsets the order of the lines 
in the original (B.txt) when it sorts them.

Cheers,

	- Miriam
-- 
If you don't have any failures then you're not trying hard enough.
  - Dr. Charles Elachi, director of NASA's Jet Propulsion Laboratory
-----
Website: http://miriam-english.org
Blogs:   http://miriam-e.dreamwidth.org
          http://miriam-e.livejournal.com



More information about the Techtalk mailing list