5

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.

Adam
  • 151

2 Answers2

3

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'
1
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.

glenn jackman
  • 27,524