General :: Search For Text Strings In Multiple PHP Files?
Feb 3, 2011
Long story short, I got a folder with nearly 800,000 php files. I would like to search each file for a string and if it exists in that file, the file gets copied to another directory. Is this possible from the terminal? So far I got: grep -i -n -r 'ppr-1792' * | cp $1 move_to_here
But this obviously doesn't work. $1 needs to be the file name that contains matching text.
Something very handy to do in a Linux shell, is manipulating files and strings - essentially parsing data. Write a utility which will scan in a text file and search and replace strings. We also want to keep track of how many strings we've replaced.
I know that my command would look like this: <utility name> <filename> <stringToSearchFor> <stringToReplaceWith> Code: #!/bin/bash
I would like to find all the files that contains the strings I'm searching.
For example (it's just an example), I would like to search all the files in "/etc" that contains "eth0" and "us", whatever where are located those 2 strings, the important is that the 2 strings are in the files listed.
It would be something like a "grep -lr 'eth0' *" and "grep -lr 'us' *" but in one time/command, so that I don't have to make a comparison of the 2 list of files resulting from the 2 "grep" commands given higher.
This should be simple but I can't seem to find what I am looking for.I want to search a text file for the existence of certain strings and execute a command if they exist, something along the lines of:
if <string> exists command or
if <any member of this list exists> command
I know how to manually search a file with grep, cat, etc., but the "if this exists" part eludes me.
I want to search and replace strings in a file with strings in other files/i need to do it with big strings(string1 is big) and i want to use a txt file for this.But this code not working :
how to search in files text that is one-byte encoding? places - search for files in gnome in ubuntu searches only utf-8 text.i know one way: install wine and total commander, then search with it. what are better ways?[URL]
Hello, I need some help searching through multiple files, finding a line and replacing that line. The line I am searching for is:
password key ******* 1222554
ultimately I want to be able to delete the numbers after the asterisks . my thoughts are to create a script that will search for the line password key ******* and delete it then replace it with password key ******* my files are located in /opt and they are all txt files.
I am using sed to process an ascii tcpdump file whereby each packet is processed into a line with the same number of columns and useful information is pulled out like the time, packet type, length, and also IP addresses, payload type and port numbers where appropriate. The time is already changed to seconds, followed by the protocol over ethernet, such as IP, IP6, ARP etc. and I can change anything it detects as IP, IP6 and ARP into some other string, pulling out necessary information depending on the protocol and payload.The beginning part of the search for IP starts with the sed search /([0-9][0-9]*.[0-9][0-9]*)[ ]IP[ ,] ... /, where time is in seconds and ellipses means more stuff, and likewise for IP6 and ARP.But how do I process the lines that are NOT IP, IP6 or ARP? (Specifically NOT /IP[ ,]/, /IP6[ ,]/ or /ARP[ ,]/.) So that I can format them into a string with the same number of columns.
Is there a faster way to search for a file containing a given string than using grep -re "string" /
This takes a long time to search through the entire system, so I was wondering if there is a faster way. I don't know the name of the file, just that it will contain a given string.
In String1 and String2 the substrings are separted by commas. The substrings which are common between String1 and String2 are ABC,DEF this common substrings has to be written to a file say common.txt ( having the text ABC,DEF). And the substrings GHI,JKL in String1 which are not present in String2 has to be written to another file say String1Extra.txt (having the text GHI,JKL). In the same way the substrings MNO,XYZ from String2 which are not present in String1 has to be written to another file say String2Extras.txt(having the text MNO,XYZ) .
I have a hidden folder with a lot of text files in it. I would like to search in this folder for all files containing a given text.The File Browser's" FIND searches only in the file names, not in their contents.The FIND function of Ubuntu does not allow me to search ONLY in the given hidden folder. So, how can I find my files within the hidden folder with the given text within them?
I am trying to search for a term in a bunch of files. Is there a way to do this. I would like to search all the files in a directory and its subdirectories for a specific term.
Trying to remove lines from a syslog text file that have duplicate strings
Mar 10 06:51:11[http-8080-1] INFO com.MYCOMPANY.webservices.userservice.web.UserServiceController [u:2533274802474744|360] Authorize [platformI$tformIdAndOs=2533274802474744|360, userRegion=America|360]
then a few lines down
Mar 10 06:52:03 [http-8080-1] INFO com.MYCOMPANY.webservices.userservice.web.UserServiceController [u:2533274802474744|360] Authorize [platformI$tformIdAndOs=2533274802474744|360, userRegion=America|360
got the same thing in terms of a u: number but the issue is I need to remove duplicates and just leave one and the file has multiple duplicates of different u: numbers and it's 14,000 lines long. can anyone tell me if I can use awk? sed? or sort for something like this to? removing lines that have a certain string in there that's a duplicate.
How to search multiple words in multiple lines, inside a directory including sub-directory? Pls. give easy example. I want to search the files (in /xx folder and all subfolders) that have header.h included and used x() function. I tried $grep -r "header.h" | grep -r "x(" /Folder/subfolder/ > search.log
How can i use different starting and ending delimiters in awk to search for strings or numbers like:
:string"another_string 'number+another_number
now i want string and number as output from above lines. But if i use delimiter as : or ' it will print the entire line coz second delimiter is not same as first one.
I've got a quick grep question. I'm trying to work out a command I can use to locate all of the files in a directory that have sql database connection details. I want to do it by looking for the strings "localhost" and the name of the database.find . -type f -exec grep -l -E '^(localhost|DATABASE_NAME)' {} ;
what command is to be used to call strings from other files to the script and then comparing strings from two different files in the script to check if strings are matched then return the result to another script.
I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.
I have a html page and I would like to search for the occurance of a given string as an anchor. Then I would like to search backward for a the first match to a given regular expression. As a result I would like to output the text between the two points.
Please note that I would like to have the output up to the first regex match before the ANCHOR point.What is the best tool to solve this?
I have done a bunch of searches on this but the terms seem to get tangled in the more popular search of "colouring the output of grep / awk". I am trying to find a way to grep/awk through the output of a command to find text of a specific colour. The command's output has a range of colours signifying too many different things to specify using text, with colour being the only form of grouping.
I want to (from the command line) be able to counte lines in a bunch of files of a specific type in a folder and all its sub-folders. How would I do this?
I'm pretty sure this is doable from the command line, but my CLI skills have degraded a lot since my pre-Y2K admin days. The goal is to search all the files in the directory for a very long string of text and replace it with another string of text. The text being searched for is my Google Adsense code (which will be stripped from my website) and it will be replaced with a placeholder so I can easily tack something else in there in the future.
Seeing how I have that long snip of code on about 100 pages, automating the process would make life easier. If I was searching for a single word, I can see ways to do this. If I paste the code I'm searching for into a text file, is there a way to: find (contents of oldstring.txt) and replace with (contents of newstring.txt)?
[Syenite] RegionUUID = 8fc56fdd-0afd-4074-9432-0ae8f42b799f Location = 9992,10007 InternalAddress = 0.0.0.0 InternalPort = 9000 AllowAlternatePorts = False ExternalHostName = 71.171.21.9 What I need to do is find out what the IP address is after "ExternalHostName ="
After that I will need to compare that IP to whatismyip and if it's different then replace it but that is easy to do with sed. I just can't figure this simple hurdle out.