I want to see the diff
between a paragraph in the middle of a file and a file containing a single paragraph.
The paragraph is on line 60
of file foo
, and file bar
contains only that paragraph with possible minor differences.
I can extract that paragraph using sed
thusly: sed -n 60,60p foo
. How can I use this in diff
?
The following don't work:
sed -n 60,60p foo | diff bar # diff: missing operand after `foo`
diff bar `sed -n 60,60p foo` # diff: extra operand `in`
I can do:
sed -n 60,60p foo >> tempfile; diff bar tempfile
Is there a solution that doesn't require me to store somewhere temporarily using a pipe?
If you use a '-' as file argument, diff
will read from stdin:
sed -n 60,60p foo | diff bar -
You could use process substitution:
diff bar <(sed -n 60,60p foo)
This can also be used to compare the output from two processes:
diff <(sed -n 60,60p bar) <(sed -n 60,60p foo)
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