Script to find & replace a multiple lines string across multiple php files and subdirectories
Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ?
The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories.
So lets say im at root/dir1/dir2/ , when i execute the script it should search and replace a piece of code on php files inside this directory and its subdirectories.
The closest i found i think it was this:
But the string i need to find and replace have multiple lines, so i dont know how to put it in this script.
Also i dont know how to save and execute this script
EDIT: AH and by the way, i need to only DELETE the piece of code from these PHP files, i dont need to replace it with something else...
Could anyone please give me detailed instructions on this ?
hi guys,
Suppose you have 100 files in a folder and you want to replace all occurances of a word say "ABCD" in those files with "DCBA", how would you do
it ???
jatin (13 Replies)
I used the following script
cd pathname
for y in `ls *`;
do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y;
done
and it worked fine for finding and replacing strings with names etc. in all files of the given path.
I'm trying to replace a string which consists of path (location of file)
... (2 Replies)
i have to search a string and replace with multiple lines.
example
Input
echo 'sample text'
echo 'college days'
output
echo 'sample text'
echo 'information on students'
echo 'emp number'
echo 'holidays'
i have to search a word college and replace the multiple lines
i have... (1 Reply)
I used the following script
cd pathname
for y in `ls *`;
do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y;
done
and it worked fine for finding and replacing strings with names etc. in all files of the given path.
I'm trying to replace a string which consists of path (location of file)
... (11 Replies)
find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g'
this is simple logic to find and replace in multiple files & folders
Hope this helps.
Thanks
Zaheer (0 Replies)
Hi,
I am creating a script to do a find and replace single/multiple lines in a file with any number of lines.
I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE
print $FIND gives
Hi How r $u
Rahul()
Note:... (0 Replies)
Can someone tell me how I can do this?
e.g:
a=$(echo -e wert trewt ertert ertert ertert erttert
erterte
rterter
tertertert
ert)
How do i replace the STRING with $a?
I try this:
sed -i 's/STRING/'"$a"'/g' filename.ext
but this don' t work (2 Replies)
I have a list of files all over a file system e.g.
/home/1/foo/bar.x
/www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g.
if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc.
There... (2 Replies)
Hello Guys,
I need to replace a string with multiple lines.
For eg:-
ABC,DEF,GHI,JKL,MNO,PQR,STU
need to convert the above as below:-
ABC,DEF,
GHI1
GHI2
GHI3,
JKL,MNO,
PQR1
PQR2
PQR3,
STU
i have tried using code as:- (2 Replies)
Discussion started by: jassi10781
2 Replies
LEARN ABOUT PHP
exec
EXEC(3) 1 EXEC(3)exec - Execute an external programSYNOPSIS
string exec (string $command, [array &$output], [int &$return_var])
DESCRIPTION exec(3) executes the given $command.
PARAMETERS
o $command
- The command that will be executed.
o $output
- If the $output argument is present, then the specified array will be filled with every line of output from the command. Trailing
whitespace, such as
, is not included in this array. Note that if the array already contains some elements, exec(3) will append
to the end of the array. If you do not want the function to append elements, call unset(3) on the array before passing it to
exec(3).
o $return_var
- If the $return_var argument is present along with the $output argument, then the return status of the executed command will be
written to this variable.
RETURN VALUES
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back
without any interference, use the passthru(3) function.
To get the output of the executed command, be sure to set and use the $output parameter.
EXAMPLES
Example #1
An exec(3) example
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>
NOTES
Warning
When allowing user-supplied data to be passed to this function, use escapeshellarg(3) or escapeshellcmd(3) to ensure that users can-
not trick the system into executing arbitrary commands.
Note
If a program is started with this function, in order for it to continue running in the background, the output of the program must be
redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
Note
When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not
allowed to have .. components in the path to the executable.
Warning
With safe mode enabled, the command string is escaped with escapeshellcmd(3). Thus, echo y | echo x becomes echo y | echo x.
SEE ALSO system(3), passthru(3), escapeshellcmd(3), pcntl_exec(3), backtick operator.
PHP Documentation Group EXEC(3)