Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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: http://pastebin.com/raw.php?i=sr20gyWz using

diff -y -W 100 hpc.sorted.new.list bduc.sorted.new.list

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 stackoverflow.com 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 hpc.sorted.new.list bduc.sorted.new.list 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
2  
I see the comm tag on the question; does that program not give you what you want? –  chepner Dec 1 '12 at 5:03
add comment

2 Answers 2

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

diff --expand-tabs -W 100 -y  hpc.sorted.new.list bduc.sorted.new.list |
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;
                   next;}1'
share|improve this answer
add comment
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" "" ;;     
    esac
done

Adjust format to suit.

share|improve this answer
add comment

Your Answer

 
discard

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.