- OK, I give up. I'm trying to search for a particular string like 'xyz' in a bunch of *.txt files located in various locations in a tree - all the folders and files I want to search in are rooted under a particular folder.
- How to search a directory tree for all files containing specific text string on Linux using the command line. This tutorial will help you to search all files matching a string recursively. This tutorial uses “grep” command to search string in files.
- Recursively Search For Text String Within Files Mac
- Search For Text String In Excel
- Search For Text String Match Ruby
Searching for text strings in a group of files. This find and grep command example can be read like this: 'Look in the current directory and all sub-directories for files ending with the characters '*.java', and when you find those files look for the string 'foo' in those files, then print the filename if the string is found.' It's a great way of merging the find and grep commands to find a text string that you know is in a file, somewhere.
If you need to find and replace the occurrence of a word, phrase, URL, or whatever, and it's in several documents, this can be a really tedious task. If you're running Mac OS X, Linux, or really any Unix-based operating system, you can use the command line to save you a lot of time and effort.
All you really need is this simple command:
perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' *.txt
The search string is what you need to alter. You want to replace SEARCH_FOR with the text you're searching for and REPLACE_WITH with the text you want to use as a replacement. You'll also want to change *.txt if you're working with HTML files (or another type of text file). This command also assumes you're in the directory you want, so you'll also need to use cd to change to the directory you want or will have to specify the full path. For example:
perl -pi -w -e 's/stupid/awesome/g;' ~/Desktop/*.txt
The above command will replace all occurrences of 'stupid' with 'awesome' found in any .txt files on the desktop. Pretty neat!
Advertisement
UNIX: Find and replace text across multiple files | Pressbin.com
Advertisement
Active5 years, 6 months ago
I have a large directory tree structure with text files (php, html, etc). I need to search for a string that occurs frequently throughout these files and flip the
to a /
. I need this to recursively traverse the entire structure. I've seen a couple of suggestions about how to do this, but I'm not able to get them to work for me.Search for:
MySitescriptsconnection.php
Replace with:
/MySite/scripts/connection.php
I tried this, but it didn't work:
AlexAlex8,2392929 gold badges108108 silver badges192192 bronze badges
Recursively Search For Text String Within Files Mac
2 Answers
Raul AndresRaul Andres
if
Fidelsed -i
option is not available, it works with simple script.Search For Text String In Excel
Fidel71711 gold badge55 silver badges1212 bronze badges