This page has been translated from Spanish

...::: Guatewireless.org ::::..

Technology, Software Libre, Guatemala, Open Source, Linux, Wireless, WiFi, Scripting, Debian, CentOS, Gentoo, Redhat, SuSE, Windows

Find and Replace text in all files in a directory and all subdirectories

If looking like replacing text in multiple files in a single line of command, have reached the right place. Many times we need to find or make changes to a given text and to start or do not know which file, document or folder may be.

Let's say you change the server IP address, and we must make the changes in all configuration files and logs where you see the old IP.

Not to be searching for hours among all the files from our server, I pass these tips to replace alphanumeric strings in linux.

  • To replace a text or string each time it appears in the files:
  •  deathbian: ~ # find / path / dir "*. txt" | xargs perl-pi-e 's / text / replacement / g'
    


  • To replace the first time it appears the text:
  •  deathbian: ~ # find / path / dir "*. txt" | xargs perl-pi-e 's / text / replacement /'
    


  • To replace all files in a directory:
  •  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: 12%

10 Comments

  1. Two days ago I'm looking for something that allows me to do this, thank you : D

    • What a great help! Indeed glad to know that there are professional people dedicated to helping others. Thank you very much for the contribution. (b): D (ci)

  2. 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 delete the user address in N documents.

  3. perl-pi.bak-e "s / favicon.ico / fernando.ico / g;" for the file configuration.php configuration.php and replace with fernando.ico favicon.ico

  4. must know how to write and explain what enl browser question

  5. as I use where I have to put a little expliken

  6. Here I give you one that replaces encontrre massive lines of text in many kinds of archivoo for TexFinderX xp 2.14 for Windows XP and Vista

Trackbacks

  1. Find and replace multiple files in a directory. - Galego
  2. Find and replace multiple files in a directory.
  3. Find and Replace multiple files directory dun. - Galego

Please enter a comment

Please note the following:
Comments are moderated, so it can take in being published. No need to repeat his comment.
Your email will never be revealed.

Search terms


  • what steps should you follow to find and replace text
  • find and replace text
  • linux replace text
  • linux search and replace
  • perl replace text
  • steps to find and replace
  • replace text in files
  • linux replace text
  • chains replace linux
  • search and replace in linux
  • replace text in multiple files gentoo
  • replace text in multiple files linux
  • java string replace
  • search and replace ubuntu
  • replace linux
  • perl replace text
  • ubuntu search for text in files
  • linux search and replace
  • find and replace text
  • replace text in multiple files
  • replace perl
  • search and replace files
  • What steps should you follow to find and replace text?
  • as replacing a file
  • search and replace in multiple files
  • linux replace text files
  • search and replace in multiple files
  • java file search string
  • linux text search within
  • find and replace text in linux
  • replace words in a file java
  • linux file-word change
  • shell replaces strings in files
  • replace text in a file linux
  • replace in unix file
  • linux replace
  • seek to replace ubuntu
  • steps to replace a text
  • as massively replace text in linux
  • perl-pi
  • perl search and replace
  • find and replace text in files linux
  • search for text within a file
  • shell search within files
  • search replace files
  • search replace bash
  • perl replace text
  • find a text in multiple files ubuntu
  • search and replace text in unix
  • replace text in perl
  • search replace bash
  • search for text in all files in a directory
  • replacement strings
  • search for text inside php
  • search for text in directory
  • replace text in unix
  • perl search and replace
  • Java search and replace
  • as search for text in directory
  • STEPS TO REPLACE AND SEEK