[CALUG] Best programming app

Jim Bauer jfbauer at comcast.net
Tue Nov 22 19:42:06 CST 2005

On Tuesday 22 November 2005 08:55, Josiah Ritchie wrote:
> It probably looked something like this (I don't have Linux available
> atm so can't check it):
> sort first.csv > one.csv
> sort second.csv > two.csv
> diff one.csv two.csv | grep -e (^>|^<) | sort > differences.text
> The (^<|^>) part is a regexp, indicated by the -e before it. It tells
> grep to find any lines that start with either < or >. The ^ indicates
> the beginning of the line. The () bring together a collection of
> things and the | indicates the break between elements.
> grep's input comes in through the | before it and goes out to sort
> through the | after it. The > pops the end results of sort into a file
> called differences.text.
> Some folks more handy than I could probably make this one line instead
> of three. Anyone want to mess with that?. I always enjoy a good
> disection of my commands. :-)

Try something like this...

$ diff <(sort first.csv) <(sort second.csv) | egrep '(^>|^<)' | sort > diffs

For the <(cmd) syntax see 'Process Substitution' in the bash manpage.
Basically the <(cmd) will be replaced with a file name that diff will
see.  The output from the cmd will be written to that file (a pipe).

To see what is going on try these.

$ echo <(date)
$ cat <(date)
Tue Nov 22 20:36:43 EST 2005

More information about the lug mailing list