Gentoo Archives: gentoo-user

From: Helmut Jarausch <jarausch@××××××××××××××××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Multi-file search & replace of text
Date: Mon, 01 Mar 2010 08:48:01
Message-Id: tkrat.6b94e559aca88162@igpm.rwth-aachen.de
In Reply to: [gentoo-user] Multi-file search & replace of text by Stroller
1 On 28 Feb, Stroller wrote:
2 > Hi there,
3 >
4 > If I want to automagically replace text in a file, I can use `sed`. I don't believe that `sed` can be invoked in such a way to change the file in place, therefore two commands are necessary:
5 >
6 > $ sed 's/Project Gutenberg/Wordsworth Classics/' foo > bar
7 > $ mv bar foo
8 > $
9 >
10 > Using `grep` I can search *recursively* through directories to find the text I'm looking for. EG: `grep -R Gutenberg ~`
11 >
12 > I would like to find every instance of $foo in a directory hierarchy and replace it with $bar.
13 >
14 > Is there any tool that will combine all these operations for me?
15 >
16 > If not, what is the best way to string together grep and sed so that they'll do what I want?
17 >
18
19 You might have a look at an old program which is still quite useful
20 The link in the following web page is broken!
21 http://centoshacker.com/kabir/utility/global-search-and-replace-using-the-fgres-utility.html
22 Download from
23 http://wiki.uni-konstanz.de/pitz/fgres.html
24
25 Helmut.
26
27 --
28 Helmut Jarausch
29
30 Lehrstuhl fuer Numerische Mathematik
31 RWTH - Aachen University
32 D 52056 Aachen, Germany