[Nottingham] A little scripting on a Sunday evening (help please)

Joshua Lock incandescant at gmail.com
Sun Apr 9 20:03:29 BST 2006


On 9 Apr 2006, at 19:40, Michael Simms wrote:
> On Sun, 2006-04-09 at 18:30 +0100, Joshua Lock wrote:
>> Afternoon folks,
>>
>> <STORY>
> <snip>
>> </STORY>
>>
>> <PROBLEM>
>> The files all have the suffix .html and all link to each other...
>> </PROBLEM>
>>
>> I'm looking to have some script iterate through all of sites
>> directory tree and rename the files from *.html to *.php. I then want
>> the script (or a different script) to (regular expression?) scan the
>> files for anchor tags and convert the .html suffixes to .php.
>
> The second part is a little harder than the first, but assuming all of
> the occurrences of .html want to be converted to .php...
>
> find . -name "*.html" -exec ./doit.sh \{\} \;
>
> Where doit is a script contining
>
>
> #!/bin/sh -
>
> cat $1 | sed -e "s/\.html/\.php/g" > /tmp/fixing
> mv /tmp/fixing $1
>
> mv $1 `echo $1 | sed -e "s/html$/php/"`

That would do it if not for the spaces in file names...
After a quick man find I thought adding -print0 might help, alas no...

>
>> I'm not asking someone to write such a script for me (although I
>> would gratefully and gladly accept and existing solution);
>
> You caught me in between jobs {:-) Shell scripting is fun and it  
> sounded
> like a good 5 minute challenge and indeed it was {:-)

Dost thou never stop working young Michael?
I appreciate you taking the time :)

>> just some
>> pointers to documentation to help me do this or even a hint at what
>> tools to use?
>
> sed is your friend. Others may do it with awk, but I find sed easier.

In which case I'll take sed out and get to know him/her

>> I haven't touched regular expressions but need to learn some time,
>> I'm also thinking of delving into Perl so any pointers in that
>> direction would be gratefully accepted :)
>
> Duncan did some good perl talks, I dunno if the notes from that are
> still available?

That would be nice, I saw one but it was years ago ...

Andy; thanks for your reply but I don't seem to have a command called  
rename and man rename gives me info on a C header...




More information about the Nottingham mailing list