#!/bin/sh # Remove trailing whitespace. By default it runs # in the current directry, on all files, but you # can change this by passing parameters as you # would to find. # # License: LGPLv2 # # Note this doesn't change file (timestamps) # which don't need to be updated. #Note super sed has a -i option to do this (edit files in place) #also perl can edit files in place easily. # Temporary file setvar temp = "/tmp/runsed$Pid" find @ARGV -type f -print | while read file { echo -n "editing $file: " if test -s $file { sed -e 's/[ ]*$//g' <$file > $temp if test -s $temp { if cmp -s $file $temp { echo -n "file not changed: " } else { cp $temp $file } echo "done" } else { echo "produced an empty file - aborting" } } else { echo "original file is empty." } } echo "all done" rm -f $temp