Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This has been getting the good half of my day and I am sure such a solution must exist (if not, then I am programming one), but alas, here is the question.

I have two files, hpc.sorted.modules.txt and bduc.sorted.modules.txt. What I want to accomplish is show a side by side comparison of the two files where any changes that are not in either file are on its empty column. I do not want diff to append to the same line with > < or | if they do not match.

Example output: using

diff -y -W 100

To further stress the point, if you look at the example, the line:

bfast/0.7.0a                      | bedtools/2.6.1

should not exist. Rather, they should be on separate lines with an empty row in either the left or right column.

share|improve this question

migrated from Dec 5 '12 at 2:25

This question came from our site for professional and enthusiast programmers.

is vimdiff an option? – gniourf_gniourf Nov 30 '12 at 22:44
@gniourf_gniourf Yes vimdiff or sdiff or comm or any other program/script is a solution. However running vimdiff still provides me with the issue I mentioned above (the bfast/0.7.0a line my original post) – Adam Nov 30 '12 at 22:50
I see the comm tag on the question; does that program not give you what you want? – chepner Dec 1 '12 at 5:03

Assuming that screen width (-W option) is even, try the following

diff --expand-tabs -W 100 -y |
awk -v W=100 '(substr($0,W/2,1)=="|")
                  {left=substr($0,1,(W/2)-1);print left "<";
                   right=substr($0,(W/2)+1);printf "%" ((W/2)-1) "s>%s\n"," ", right;
share|improve this answer
format="%-50s | %-50s\n"
comm --output-delimiter=: hpc.sorted.modules.txt bduc.sorted.modules.txt |
while IFS= read -r line; do      
    case $line in
        ::*) line=${line#::}; printf "$format" "$line" "$line" ;;
        :*)  line=${line#:};  printf "$format" "" "$line" ;;
        *)                    printf "$format" "$line" "" ;;     

Adjust format to suit.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.