Gentoo Archives: gentoo-user

From: Stroller <stroller@××××××××××××××××××.uk>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Multi-file search & replace of text
Date: Sun, 28 Feb 2010 19:06:01
Message-Id: 12D9E0BF-AAC8-4D2D-9047-8DA47214B5A2@stellar.eclipse.co.uk
1 Hi there,
2
3 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:
4
5 $ sed 's/Project Gutenberg/Wordsworth Classics/' foo > bar
6 $ mv bar foo
7 $
8
9 Using `grep` I can search *recursively* through directories to find the text I'm looking for. EG: `grep -R Gutenberg ~`
10
11 I would like to find every instance of $foo in a directory hierarchy and replace it with $bar.
12
13 Is there any tool that will combine all these operations for me?
14
15 If not, what is the best way to string together grep and sed so that they'll do what I want?
16
17 Many thanks for reading,
18
19 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 Helmut Jarausch <jarausch@××××××××××××××××.de>