#!/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 global 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 (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:temp) op: Equal rhs: {(/tmp/runsed) ($ VSub_Dollar "$$")} spids: [41] ) ] spids: [41] ) (Pipeline children: [ (C {(find)} {(DQ ($ VSub_At "$@"))} {(-type)} {(f)} {(-print)}) (While cond: [(C {(read)} {(file)})] body: (DoGroup children: [ (C {(echo)} {(-n)} {(DQ ("editing ") ($ VSub_Name "$file") (": "))}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {(-s)} {($ VSub_Name "$file")}) terminator: ) ] action: [ (SimpleCommand words: [{(sed)} {(-e)} {(SQ <"s/[ \t]*$//g">)}] redirects: [ (Redir op_id: Redir_Less fd: -1 arg_word: {($ VSub_Name "$file")} spids: [100] ) (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$temp")} spids: [103] ) ] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(test)} {(-s)} {($ VSub_Name "$temp")}) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(cmp)} {(-s)} {($ VSub_Name "$file")} {($ VSub_Name "$temp")} ) terminator: ) ] action: [(C {(echo)} {(-n)} {(DQ ("file not changed: "))})] spids: [-1 131] ) ] else_action: [ (C {(cp)} {($ VSub_Name "$temp")} {($ VSub_Name "$file")}) ] spids: [143 153] ) (C {(echo)} {(DQ (done))}) ] spids: [-1 117] ) ] else_action: [(C {(echo)} {(DQ ("produced an empty file - aborting"))})] spids: [163 173] ) ] spids: [-1 89] ) ] else_action: [(C {(echo)} {(DQ ("original file is empty."))})] spids: [176 186] ) ] spids: [66 188] ) ) ] negated: False ) (C {(echo)} {(DQ ("all done"))}) (C {(rm)} {(-f)} {($ VSub_Name "$temp")}) ] )