Date: Fri, 28 Jan 2005 12:04:37 +0100 From: Anthony Atkielski <atkielski.anthony@wanadoo.fr> To: freebsd-questions@freebsd.org Subject: Re: One-line global string replace in all files with sed (or awk?) Message-ID: <1802109563.20050128120437@wanadoo.fr> In-Reply-To: <20050128064057.GB1559@gothmog.gr> References: <1098984237.20050128065616@wanadoo.fr> <20050128064057.GB1559@gothmog.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
Giorgos Keramidas writes: GK> grep will do. You just have to pass it the right option: GK> GK> find . -type f | xargs grep -l 'foo' | \ GK> xargs sed -i '' -e 's/foo/bar/g' GK> GK> When passed the -l option (this is a lowercase 'EL'), it will not print GK> the matched lines. Only the name of the files that *do* match. Then, GK> once you have a list of files that really do match with 'foo' as a GK> pattern, you can xargs sed on the list to substitute whatever you want :-) It's interesting that there are multiple ways to do this in FreeBSD, whereas I've never found a way to do it in Windows, even with the fancy Visual InterDev I've been using for several years (it will _search_ for strings in multiple files, but it won't do replacements, so you have to search and then edit each file by hand--try doing this several hundred times, several times in a row sometime!). -- Anthony
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1802109563.20050128120437>