[Techtalk] finding added lines in a file
Chris Wilson
chris+linuxchix at aptivate.org
Fri Aug 16 08:43:03 UTC 2013
Hi Miriam,
On Fri, 16 Aug 2013, Miriam English wrote:
> Thanks Bonnie. That's very cool. I wouldn't have thought of using grep like
> that.
>
> One problem I've noticed with my solution and yours is that if a new line is
> added to B that happens to be the same as an existing line elsewhere in A it
> is lost. For example, say A and B are revisions of a story and both versions
> have a line '"Yes," she said.' early in both files, if there is another new
> line added to B later with the same wording, but unrelated to the original,
> so it is truly a new line, it is nevertheless lost. It is, of course, because
> of the sort, which removes context, which is why I've been trying to fathom
> the manuals of cmp, diff, and comp. I normally like reading manuals...
In that case, try "diff -u A.txt B.txt".
You can use grep to find only the added lines, and sed to remove the
'+' signs if you want. For example:
diff -u A.txt B.txt | grep '^+' | sed -e 's/^+//'
Cheers, Chris.
--
Aptivate | http://www.aptivate.org | Phone: +44 1223 967 838
Citylife House, Sturton Street, Cambridge, CB1 2QF, UK
Aptivate is a not-for-profit company registered in England and Wales
with company number 04980791.
More information about the Techtalk
mailing list