Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Jul 2003 13:26:59 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        "Jack L. Stone" <jackstone@sage-one.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Replacing string in multiple files
Message-ID:  <20030710182658.GC49845@dan.emsphone.com>
In-Reply-To: <3.0.5.32.20030710123009.0135fe88@sage-one.net>
References:  <3.0.5.32.20030710123009.0135fe88@sage-one.net>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Jul 10), Jack L. Stone said:
> Am running FBSD.4.8-R
> 
> At times, I need to replace an existing string in a file that has the same
> name in all ~user accounts and know there must be a short script to do that
> and suspect it involves sed(1). However, had no luck getting it to work
> yet. Basically want to do this:
> 
> - find same files in all ~users by same name "~users/myfile"
> - replace this ${string} with this ${string} in the above files
> - report list of above files modified successfully

If all your users share a common hierarchy:

sed -i.bak -e s/oldstring/newstring/ /home/*/myfile

You'll need to be running FreeBSD 4.7 or newer for sed -i to work.  Not
sure how to get a list of changed files, though.  Maybe just do a grep
beforehand?

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030710182658.GC49845>