0

I need to replace several chunks of text inside some php scripts...

i have:

find . -name 'products.php' -exec grep --silent 'TEXT_TO_FIND' {} \; -exec ls {} \; -exec sed -i 's/TEXT_TO_FIND/REPLACE_TEXT/g' {} \;

this work, but i have text of about 2 ou 3 lines..

so i remember to create a find.txt with my find text and another replace.txt with the replacement text..

my question is.. how can i use this files as inputs in the above command..

something like:

find . -name 'products.php' -exec grep --silent `cat find.txt` ...

Best regards Bruno

DerfK
  • 19,493
  • 2
  • 38
  • 54

2 Answers2

0

Unfortunately i can't come to a specific command, but maybe xargs utility will come in handy. It executes lines of the text file or stdin as commands. For example, following command prints file information about all files in current directory:

/bin$ ls | xargs file
bash:             ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x6c2d022503edd4e409032f33bffbcb66d2546ea5, stripped
...
yaromir
  • 101
  • 3
0

Not sure I understood the question, but if you mean you want to find/change several items in a single command, maybe this answers your needs:

find . -name "*.php" -exec grep -l -E 'finditem1|finditem2|finditem3' {} \; -exec sed -i -e "s/finditem1/replitem1/" -e "s/finditem2/replitem2/" -e "s/finditem3/replitem2/" {} \;

Also, both grep and sed accept files as inputs, but you'll have to create 2 distinct files for grep matches and sed commands. Alternatives may exist also with awk or perl.

tonioc
  • 1,047
  • 8
  • 11