baslinux AT lists.ibiblio.org
Subject: Baslinux mailing list
List archive
Re: [BL] bash help; changing case of file names, hyperlinks
- From: Lee Forrest <lforrestster AT gmail.com>
- To: BL listserv <baslinux AT lists.ibiblio.org>
- Subject: Re: [BL] bash help; changing case of file names, hyperlinks
- Date: Fri, 23 Feb 2007 17:42:02 +0000
On Fri, Feb 23, 2007 at 01:03:21PM -0600, James Miller wrote:
> I've run across a problem that a bash script might resolve. But my bash
> skills are
> rudimentary at best. I'd therefore like to ask for help with this project.
> I've
> downloaded a grouping of html files I want to have resident on my home
> computer. The
> files are linked together in series and link one to another from within
> each html file
> as well as from some centralized index pages. The problem is that this
> grouping of
> files was created by some (not too bright) M$ user who paid little or no
> attention to
> case sensitivity. Sometimes file names are in lower case, sometimes in
> upper case
> (mostly upper case). The problem, as should be clear, is that the links
> don't work on
> a Linux system if the case is not properly specified in the hyperlink. What
> I
> therefore need to do is convert the relevant file names, whether under
> their resident
> directory, or within the html files themselves, to either upper or lower
> case. It
> could be alot more complex to do this if the file names varied more than
> they do, but
> as things stand, there are only 5 words that need their case changed.
>
> For demonstration purposes, let's say that the relevant words are index,
> htm, word1,
> word2, and word3. What would be the automated way to change all instances
> of index,
> htm, word1, word2, and word3 to INDEX, HTM, WORD1, WORD2, and WORD3?
> I suppose the routine for doing this would be different for
> renaming the files than it would be for changing the case of
> hyperlinks inside an html file.
Only the sed part of the script would differ.
> Any help on this would be much
> appreciated.
This script should work as is (when you fill it in). But be sure
to test it first in a directory you create for the purpose with
copies of some or all of the files in question in it.
#!/bin/sh
dir=[where the files are - include trailing forward slash]
for _file_ in
#list files, space seperated; same single line; include prefix
#$dir
#${dir}$_file -- if all files in dir, the do use ${dir}*
#etc ; wildcards - sed uses regular expressions
do cat $_file | \
sed -e 's/index/INDEX/g' \
-e 's/htm/HTM/g' \
#and so on
> tmp/xa2923
mv /tmp/xa2923 ${dir}$_file
done
For bash newbies, put that in a file and make it executable with:
--------------
chmod +rx file #name it anything
--------------
Then run it by putting the full path on the commandline:
-------------
/home/you/file # for example
-------------
Of course, if there are other instances of those strings in the files,
they'll be
changed too. I just don't think it matters.
A more complex sed script would fix that.
Lee
--
BasicLinux: Small is Beautiful
http://www.basiclinux.com.ru
-
Re: [BL] bash help; changing case of file names, hyperlinks
, (continued)
- Re: [BL] bash help; changing case of file names, hyperlinks, sindi keesan, 02/25/2007
- [BL] USING SED TO SUBSTITUTE: was Re: bash help; changing case of file names, hyperlinks, sindi keesan, 02/25/2007
- Re: [BL] USING SED TO SUBSTITUTE: was Re: bash help; changing case of file names, hyperlinks, Lee Forrest, 02/25/2007
- Re: [BL] bash help; changing case of file names, hyperlinks, 3aoo-cvfd, 02/25/2007
- Re: [BL] bash help; changing case of file names, hyperlinks, sindi keesan, 02/25/2007
- Re: [BL] bash help; changing case of file names, hyperlinks, Karolis Lyvens, 02/25/2007
-
Re: [BL] bash help; changing case of file names, hyperlinks,
sindi keesan, 02/24/2007
- [BL] Scripts Using Sed (was: bash help; changing case of file names, hyperlinks) 56, Lee Forrest, 02/24/2007
- Re: [BL] bash help; changing case of file names, hyperlinks -- corrections, Lee Forrest, 02/24/2007
Archive powered by MHonArc 2.6.24.