Find and Replace text in all the files into a directory and all subdirectories
If you were looking for as replacing text within multiple files into a single line of command, have reached the right place. Many times we have to find or make changes to a text given to start and we do not know, nor in any file, document or directory can be.
Let's say you change IP address to the server, and it is necessary to make changes in all configuration files and logs which show the IP earlier.
To not be looking for hours among all the files on our server, move them to replace these tips on linux Alphanumeric strings.
- To replace a text string or wherever they appear in the files:
- To replace the first time you see the text:
- To replace all the files into a directory:
deathbian: ~ # find / path / directory "*. txt" | xargs perl-pi-e 's / text / replacement / g'
deathbian: ~ # find / path / directory "*. txt" | xargs perl-pi-e 's / text / replacement /'
deathbian: ~ # for arg in `` ls-C1; do perl-pi-e 's / text / replacement / g'; done;
There are a lot of combinations possible using the shell command line. Take the first search:
deathbian: ~ # for arg in `find / your / home / dir-name" *. txt "`; do perl-pi-e 's / text / replacement / g' $ arg; done;
Popularity: 45% [?]
6 comments to "Find and Replace text in all the files into a directory and all subdirectories"
Trackback URI | Comments RSS







on 12 Feb 2008 at 5:47 pm # cannot
For two days I'm looking for something to let me do this, a thousand thanks
[Reply]
Reyes responded on June 5th, 2008:
That good help!, Really glad to know that there are professional people dedicated to working with others. Thank you very much for the contribution. (b): D (ci)
[Reply]
on 14 Nov 2008 at 2:35 pm # Find and Replace multiple files in a directory. - Galego
[...] Guatewireless Click here to help. Items related RapidSpread: Sobe os TEUs files and [...]
on 14 Nov 2008 at 2:36 pm # Find and Replace multiple files in a directory.
[...] Via: Guatewireless [...]
on 14 Nov 2008 at 2:39 pm # Find and Replace multiple files dun directory. - Galego
[...] Guatewireless Click here to help. Items related RapidSpread: Sobe os TEUs files and [...]
on 16 Dec 2008 at 10:33 am # fher98
To replace email addresses in the configuration of exim use;
find / etc / exim / * | xargs perl-pi-e 's / user \ @ dominio.com / / g'
and with that I can clear the direction in N-user documents.
[Reply]