#!/bin/csh -f # splitdiff # ------------------------------------------------------------------------- # Shell script to split lines of specified files at specified char(s), # and then compare them, optionally sorting first. This is useful when # comparing files containing PATH or CLASSPATH variables, for example. # ------------------------------------------------------------------------- # Revision History: # $Log$ # ------------------------------------------------------------------------- if ($#argv < 3 || $1:q == "-h" || $1:q == "--help") then echo "Usage: $0:t [-s] char(s) file1 file2" echo "Options:" echo " -s = Sort the split files before comparing" echo "Example: $0:t : file1_containing_PATH file2_containing_PATH" echo "Example: $0:t := file1_containing_PATH file2_containing_PATH" echo "Example: $0:t -s := file1_containing_PATH file2_containing_PATH" exit 1 endif # Collect command line options set sort_option = "false" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then shift # If help option was anywhere among the options, call recursively # with just that option, and exit. $0:t --help exit 1 else if ("$1" == "-s") then shift set sort_option = "true" else # Not a recognized option. Assume it's the first parameter break endif end if ($#argv < 3) then $0:t --help exit 1 endif set timestamp = `date "+%Y_%m_%d__%H_%M_%S"` set tempfile1 = /tmp/$0:t_1_$$_$timestamp set tempfile2 = /tmp/$0:t_2_$$_$timestamp if ("$sort_option" == "true") then cat $2:q | split_at_chars $1 | sort > $tempfile1 cat $3:q | split_at_chars $1 | sort > $tempfile2 else cat $2:q | split_at_chars $1 > $tempfile1 cat $3:q | split_at_chars $1 > $tempfile2 endif windiff $tempfile1 $tempfile2 rm $tempfile1 $tempfile2