[Nottingham] A little scripting on a Sunday evening (help please)
Michael Simms
michael at tuxgames.com
Sun Apr 9 19:40:42 BST 2006
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/"`
> 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 {:-)
> 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.
> 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?
> I really don't fancy doing this by hand :s
>
> Best wishes,
>
> J
> --
> Joshua Lock
> incandescant at googlemail.com
>
> _______________________________________________
> Nottingham mailing list
> Nottingham at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/nottingham
--
Michael Simms - CEO, Tux Games
http://www.tuxgames.com
More information about the Nottingham
mailing list