Re: In need of a SHELL Script - Please!!!

From: Alexander Dünisch (phaedrus_at_gmx.net)
Date: 10/28/03


Date: Tue, 28 Oct 2003 20:54:15 +0100

On Tue, 21 Oct 2003 15:55:45 -0400, rbristol
<member45122@dbforums.com> wrote:

>
>I'm not terribly familiar with shell scripting and would like to know if
>someone has a script that loops through the files in a directory and
>replaces the first 3 letters of the file name while leaving the last 20
>characters the same.
>
>
>
>For example change 'OLD_01012003_101000.xls' to
>'NEW_01012003_101000.xls' (note that the 'new' and 'old' are consistent
>values that do not vary...but the time stamp does).
>
>
>
>Please let me know.
>
>
>
>(frustrated)...
>
>RBB

# sh,bash,ksh

cd directory_where_your_files_are

typeset -a old=(`ls OLD*`)
typeset -a new=()

for index in `seq -s " " 0 \`expr ${#old[@]} - 1\`` do

        new[index]=`echo ${old[index]} | sed 's/OLD/NEW/'`
        mv ${old[index]} ${new[index]}

done



Relevant Pages

  • Re: In need of a SHELL Script - Please!!!
    ... rbristol wrote: ... > I'm not terribly familiar with shell scripting and would like to know ... > if someone has a script that loops through the files in a directory ...
    (comp.unix.shell)
  • In need of a SHELL Script - Please!!!
    ... I'm not terribly familiar with shell scripting and would like to know if ... someone has a script that loops through the files in a directory and ... RBB ...
    (comp.unix.shell)
  • Re: In need of a SHELL Script - Please!!!
    ... > I'm not terribly familiar with shell scripting and would like to know if ... > someone has a script that loops through the files in a directory and ... Regards, ...
    (comp.unix.shell)
  • Re: In need of a SHELL Script - Please!!!
    ... On Tue, 21 Oct 2003 at 19:55 GMT, rbristol wrote: ... > I'm not terribly familiar with shell scripting and would like to know if ... My code in this post is copyright 2003, Chris F.A. Johnson ...
    (comp.unix.shell)
  • Re: expr problem , checking numbers are in sequence
    ... On 2007-02-23, Stephane CHAZELAS wrote: ... Using "while read" loops is very bad shell scripting practice. ...
    (comp.unix.shell)