[help]Delete or replace text in multiple file and multiple directory
here's the case :
almost of php/html file on my site has added the text :
I don't know how this happen, so i want to remove above text from all of my php/html.
i have tried this following script :
Above script was works but only in the directory where i run the script, i want all files in subdirectory too, anyone can help me?
Hello all
I need to search and replace in multiple files that are in directory hierarchy
Im using the :
find . -name "*.dsp" -print | xargs grep -n -o Test.lib" , I like to be able to replace every instance of Test.lib
with empty space .
how can I write one liner that does this ? (3 Replies)
I would like to know code that will delete multiple text from a comma delimited file. For example, how would the comma delimited file below delete the word 'PEST' in Perl language (previously an excel file that was converted to a csv and the last column was PEST):
1, 2,43,34, bosx,PEST
1,... (1 Reply)
Ok guys,
If anyone could help me out on this puppy I'd be very appreciative!
Here's the scenario
I have a string for example :
<img src=BLANK_IMG border=0 width=221 height=12>
or
<img src=IMG border=0 height=12 width=221 >
or anything else really....
need to basically change each... (10 Replies)
Dear all
My task is to replace a strings in multiple files.
filename: file1
I can use sed to replace abc.server.com to unix.server.org
e.g. sed 's/abc.server.com/unix.server.org/g file1 > newfile1
I have 2 questions. How do I
directly save file1 instead of append to newfile1. I... (1 Reply)
I need to replace a piece of text in many files, recursively, in a way that doesn't duplicate the files. How would I do that?
The closest I've come is
grep -rl "text" * | sed -e 's/home1/home2/g'
but that just replaces the filename. (2 Replies)
I need to replace (delete) a text block in a bunch of files, its a html table, almost at the end of pages but the location varies.
In Windows I used Filemonkey, but nothing like that in Unix?
There is replace from mysql, but how does it deal with newlines?
sed only works with single lines,... (6 Replies)
can anyone please help me in the below scenario:
File1:
Hello1
Hello1
i want to use sed to replace multiple occurances of Hello1 in file 1 to welcome.
Thanks a ton for the help (9 Replies)
I need to update about 2400 files in a directory subtree, with a new directory path inside the files
I need to change this occurence in all files: /d2/R12AB/VIS/apps/tech_st/10.1.2
with this: /u01/PROD/apps/apps_st/10.1.3
I know how to change single words using "find . -type f -print0 |... (6 Replies)
I need help.
I have to delete multiple directories inside a directory that are two weeks old.
Example: Today is July 09, 2012
Folder1 > folder1 (created June 4, 2012) -- should be deleted
> folder2 (created June 2, 2012) -- should be deleted
> folder3 (created... (4 Replies)
Hi,
I have a file containing list of strings like
i:
Pink
Yellow
Green
and I have file having list of file names in a directory
j :
a
b
c
d
Where j contains of a ,b,c,d are as follows
a:
Pink (3 Replies)
Discussion started by: madabhg
3 Replies
LEARN ABOUT PHP
preg_replace_callback
PREG_REPLACE_CALLBACK(3) 1 PREG_REPLACE_CALLBACK(3)preg_replace_callback - Perform a regular expression search and replace using a callbackSYNOPSIS
mixed preg_replace_callback (mixed $pattern, callable $callback, mixed $subject, [int $limit = -1], [int &$count])
DESCRIPTION
The behavior of this function is almost identical to preg_replace(3), except for the fact that instead of $replacement parameter, one
should specify a $callback.
PARAMETERS
o $pattern
- The pattern to search for. It can be either a string or an array with strings.
o $callback
- A callback that will be called and passed an array of matched elements in the $subject string. The callback should return the
replacement string. This is the callback signature:
string handler (array $matches) You'll often need the $callback function for a preg_replace_callback(3) in just one place. In
this case you can use an anonymous function to declare the callback within the call to preg_replace_callback(3). By doing it this
way you have all information for the call in one place and do not clutter the function namespace with a callback function's name
not used anywhere else.
Example #1
preg_replace_callback(3) and anonymous function
<?php
/* a unix-style command line filter to convert uppercase
* letters at the beginning of paragraphs to lowercase */
$fp = fopen("php://stdin", "r") or die("can't read stdin");
while (!feof($fp)) {
$line = fgets($fp);
$line = preg_replace_callback(
'|<p>s*w|',
function ($matches) {
return strtolower($matches[0]);
},
$line
);
echo $line;
}
fclose($fp);
?>
o $subject
- The string or an array with strings to search and replace.
o $limit
- The maximum possible replacements for each pattern in each $subject string. Defaults to -1 (no limit).
o $count
- If specified, this variable will be filled with the number of replacements done.
RETURN VALUES preg_replace_callback(3) returns an array if the $subject parameter is an array, or a string otherwise. On errors the return value is NULL
If matches are found, the new subject will be returned, otherwise $subject will be returned unchanged.
CHANGELOG
+--------+---------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------+
| 5.1.0 | |
| | |
| | The $count parameter was added |
| | |
+--------+---------------------------------+
EXAMPLES
Example #2
preg_replace_callback(3) example
<?php
// this text was used in 2002
// we want to get this up to date for 2003
$text = "April fools day is 04/01/2002
";
$text.= "Last christmas was 12/24/2001
";
// the callback function
function next_year($matches)
{
// as usual: $matches[0] is the complete match
// $matches[1] the match for the first subpattern
// enclosed in '(...)' and so on
return $matches[1].($matches[2]+1);
}
echo preg_replace_callback(
"|(d{2}/d{2}/)(d{4})|",
"next_year",
$text);
?>
The above example will output:
April fools day is 04/01/2003
Last christmas was 12/24/2002
Example #3
preg_replace_callback(3) using recursive structure to handle encapsulated BB code
<?php
$input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
function parseTagsRecursive($input)
{
$regex = '#[indent]((?:[^[]|[(?!/?indent])|(?R))+)[/indent]#';
if (is_array($input)) {
$input = '<div style="margin-left: 10px">'.$input[1].'</div>';
}
return preg_replace_callback($regex, 'parseTagsRecursive', $input);
}
$output = parseTagsRecursive($input);
echo $output;
?>
SEE ALSO
PCRE Patterns, preg_quote(3), preg_replace(3), preg_last_error(3), Anonymous functions, information about the callback type.
PHP Documentation Group PREG_REPLACE_CALLBACK(3)