Gentoo Archives: gentoo-user

From: Stroller <stroller@××××××××××××××××××.uk>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Multi-file search & replace of text
Date: Sun, 28 Feb 2010 21:42:29
Message-Id: 0DC3E0A4-A6FF-4352-967B-1990534113B6@stellar.eclipse.co.uk
In Reply to: Re: [gentoo-user] Multi-file search & replace of text by Etaoin Shrdlu
1 On 28 Feb 2010, at 19:06, Etaoin Shrdlu wrote:
2 > On Sunday 28 February 2010, Stroller wrote:
3 >> ...
4 >> $ sed 's/Project Gutenberg/Wordsworth Classics/' foo > bar
5 >> $ mv bar foo
6 >> $
7 >
8 > Have a look at sed's "-i" option.
9 >
10 >> Using `grep` I can search *recursively* through directories to find
11 >> the
12 >> text I'm looking for. EG: `grep -R Gutenberg ~`
13 >>
14 >> I would like to find every instance of $foo in a directory
15 >> hierarchy and
16 >> replace it with $bar.
17 >>
18 >> ...
19 > A starting point could be (after you make a backup of the whole tree)
20 >
21 > find /basedir -type f -exec sed -i 's/foo/bar/g' {} +
22
23 Many thanks - that looks great!
24
25 My only concern is that it is unreliable enough that you state the
26 need to backup first. ;)
27
28 Stroller.

Replies

Subject Author
Re: [gentoo-user] Multi-file search & replace of text Etaoin Shrdlu <shrdlu@×××××××××××××.org>
Re: [gentoo-user] Multi-file search & replace of text stosss <stosss@×××××.com>