Related

Denic

File comparison tools

Apache access log file

Quad Boot

Linux commands

Featured

Enea (Ersan Elmasa)

Name

Baby

I AM GETTING MARRIED

Fuck biology

Things I would like to do before death

Newest

IE 6 on Ubuntu 9.10

Enea (Ersan Elmasa)

Name

Return false

Baby

Random

Hattrick - IV.17 - Ersan 4 : 0 PatkovachaLand

File comparison tools

Honeymoon in Dubai IV

Advice

Gradacac (born in) II

SSI to php

Sunday, July 04, 2010 14:04:35

I had interesting task:
 * I had to rename all shtml files into php
 * Make all of shtml includes (<!--#include virtual="/file.shtml"-->) into php includes (<?php include("/file.php");?>)

On Linux operated server it went something like this (all recursive):
1.find . -name '*.shtml' | sed 's/\(.*\)\.shtml/mv \1.shtml \1.php/'|sh
    Rename all .shtml files into .php
find . -name '*.shtml' finds all files named .shtml
sed 's/\(.*\)\.shtml/mv \1.shtml \1.php/' sed edits list of files where s tells to replace string (*.shtml) by another (mv \1.shtml \1.php), mv is command that really does renaming while 1 takes the name of the file in the first string and puts it there
| sh takes sed output and executes it
2.find . -type f | xargs sed -i 's/.shtml/.php/g'
    Replaces .shtml within a text into .php, hence <!--#include virtual="/file.shtml"-->) becomes     <!--#include virtual="/file.php"-->)
3.find . -type f | xargs sed -i 's/<\!--#include virtual=\"/<?php include(\"\\//g'
    Similar as above making <!--#include virtual="/file.php"--> into  <?php include("/file.php"-->
4.find . -type f | xargs sed -i 's/\.php\"-->/\.php\");\?>/g'
And finally I had <?php include("/file.php");?>

* Of course, I could optimize perl regex and make it into two steps, but this was 'faster' and safer to me.



Comments

Your email address:


*Your name:


Your website:


*Please type number shown on the right side of the text box:
verification image, type it in the box

*Comment: