I have two files in which some of the lines have changed order. I would like to be able to compare these.
One website suggested something that looks like this:
diff <(sort text2) <(sort text1)
But this yields the error: Missing name for redirect.
I am using tcsh. Is the command above for a different shell?
Is there a better way?
To compare two sorted files, we use the comm command in the Linux system. The comm command is used to compare two sorted files line by line and writes three columns to standard output.
This redirection syntax is bash specific. Thus it won't work in tcsh.
You can call bash and specify the command directly:
bash -c 'diff <(sort text2) <(sort text1)'
Here's a function for it:
function diffs() { diff "${@:3}" <(sort "$1") <(sort "$2") }
Call it like this:
diffs file1 file2 [other diff args, e.g. -y]
Presumably you could alter it as per David Schmitt's answer if necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With