1 |
On Sun, Feb 28, 2010 at 4:41 PM, Stroller |
2 |
<stroller@××××××××××××××××××.uk> wrote: |
3 |
> |
4 |
> On 28 Feb 2010, at 19:06, Etaoin Shrdlu wrote: |
5 |
>> |
6 |
>> On Sunday 28 February 2010, Stroller wrote: |
7 |
>>> |
8 |
>>> ... |
9 |
>>> $ sed 's/Project Gutenberg/Wordsworth Classics/' foo > bar |
10 |
>>> $ mv bar foo |
11 |
>>> $ |
12 |
>> |
13 |
>> Have a look at sed's "-i" option. |
14 |
>> |
15 |
>>> Using `grep` I can search *recursively* through directories to find the |
16 |
>>> text I'm looking for. EG: `grep -R Gutenberg ~` |
17 |
>>> |
18 |
>>> I would like to find every instance of $foo in a directory hierarchy and |
19 |
>>> replace it with $bar. |
20 |
>>> |
21 |
>>> ... |
22 |
>> |
23 |
>> A starting point could be (after you make a backup of the whole tree) |
24 |
>> |
25 |
>> find /basedir -type f -exec sed -i 's/foo/bar/g' {} + |
26 |
> |
27 |
> Many thanks - that looks great! |
28 |
> |
29 |
> My only concern is that it is unreliable enough that you state the need to |
30 |
> backup first. ;) |
31 |
|
32 |
Why are you concerned about a backup? It is always good to do backups |
33 |
before changing things. You never know when something might go wrong. |
34 |
;) |