Re: replacing text in many files

From: Martin (spam_at_away.here)
Date: 09/16/03


Date: Tue, 16 Sep 2003 17:22:46 +0200


> The return code from sed will be 0 unless there is an error. Not
> making any substitutions is not an error, so every file will still
> be moved.

What if I did something like?:

for f in *; do
  sed 's,/usr/local/bin,usr/local,g' $f > TEMPFILE
    if [ $sed -ne 1]; then
      mv TEMPFILE $f
    fi
done

> This would work:
>
> cmp "$f" TEMPFILE && mv TEMPFILE "$f"
>
> Or compare sizes:
>
> stat -c "%s" "$f" TEMPFILE | {
> read f1
> read f2
> [ $f1 -ne $f2 ] && mv TEMPFILE "$f"
> }

These are going straight into my Bash memo!!! That's powerfull stuff!

Thanks.
Martin