sed in place

By Hal Canary, 2009-11-29 00:45:32 (link)
#computers-code

#!/bin/sh
SEDCMD="$1"
shift
for x in "$@" ; do
  dirt=`dirname "${x}"`
  tmp=`mktemp "${dirt}/tmp.XXXXXXXXXX"`
  sed "${SEDCMD}" < "${x}" > "${tmp}"
  mv "${tmp}" "${x}"
  echo "$x fixed."
done

UPDATE: The next day I realized that

sed -i

does exactly the same thing.


(back)