On 26/05/2006, at 10:14 PM, Robert Thorsby wrote:

On 2006.05.26 21:47 Sam Lawrance wrote:
On 26/05/2006, at 6:50 PM, Robert Thorsby wrote:
cd /path/to/directory/
for FILE in
do
        if grep -q "text to be replaced" "$FILE"
        then
                sed -i 's/text to be replaced/replacement text/g' "$FILE"
        fi
done
Notes:
1. "grep -q" does not need to be in [test brackets] because it is a test in its own right 2. if you have filenames with spaces or funny characters it serves yourself right.
3. In case you want this to be portable, keep in mind that '-i' is a nonstandard extension. '-i' takes an argument, on my platform at least.

The argument for "-i" is optional; if supplied sed provides a backup; if not supplied sed amends the input file. See "man sed"

That is ridiculous. Unless you know in advance what the argument will be, it is not possible to detect that it has not been supplied.

Anyhow, my main point is that any form of '-i' is a nonstandard extension.

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to