Skip to Content.
Sympa Menu

baslinux - Re: [BL] bash help; changing case of file names, hyperlinks -- corrections

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • 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 -- corrections
  • Date: Fri, 23 Feb 2007 22:41:26 +0000

On Fri, Feb 23, 2007 at 05:42:02PM +0000, Lee Forrest wrote:
> 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

That shouldn't have the trailing "_".

>
> #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

#Lack of clarity.

#If all the files are in one directory, and there are no others:

for _file in /dir/*

>
> do cat $_file | \
> sed -e 's/index/INDEX/g' \
> -e 's/htm/HTM/g' \
>
> #and so on
>
> > tmp/xa2923
> mv /tmp/xa2923 ${dir}$_file
>

#That "${dir}" is redundant. The full path is already included
#in the "$_file" variable.

mv /tmp/xa2923 $_file

> done

[delete]

Lee

--
BasicLinux: Small is Beautiful
http://www.basiclinux.com.ru





Archive powered by MHonArc 2.6.24.

Top of Page