#!/bin/sh # fix: replaces arg1 with arg2 in files. It also maintains the owner/group. # # EXAMPLE fix "joe " "fred " *.txt # # changes every occurance of the string "joe " to "fred " in files ending # with ".txt" in the current directory. OLD="$1" NEW="$2" shift;shift for F in `grep -l -i $OLD $*` do sed -e "s*$OLD*$NEW*g" $F > /tmp/$F.$$ owner=`ls -l $F | awk '{ print $3 }'` group=`ls -l $F | awk '{ print $4 }'` mv /tmp/$F.$$ $F chown $owner:$group $F done