[Techtalk] finding added lines in a file
Bonnie King
b at bonnielking.com
Fri Aug 16 01:35:00 UTC 2013
grep can take a list of patterns separated by newlines.
grep -F "$(cat A.txt B.txt |sort |uniq -u)" B.txt
You'll get the added lines back in the order they appear in B.txt.
On Thu, Aug 15, 2013 at 6:59 PM, Miriam English <mim at miriam-english.org>wrote:
> 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<http://miriam-e.livejournal.com>
>
> ______________________________**_________________
> Techtalk mailing list
> Techtalk at linuxchix.org
> http://mailman.linuxchix.org/**mailman/listinfo/techtalk<http://mailman.linuxchix.org/mailman/listinfo/techtalk>
>
--
Bonnie King
More information about the Techtalk
mailing list