[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: filename manipulation



On Thursday 17 February 2005 02:39 pm, Andreas Rippl wrote:
> On Thu, Feb 17, 2005 at 11:16:27AM -0500, jeff elkins wrote:
> > Howdy,
> >
> > I need a shell script to strip X leading characters from a filename. I'm
> > using basename to change extensions, any analog of this I could use?
> >
> > #!/bin/sh
> > #
> >   for i in *.zzz; do
> >      if test -f $i; then
> >          NAME=$(basename $i .zzz)
> >          echo $NAME
> >          mv ${NAME}.zzz ${NAME}.xxx
> >  fi
> >  done
> >
> > Thanks,
> >
> > Jeff Elkins
>
> Hi Jeff,
>
> while I have seen the approach Michael has taken in the other post (and
> I see its intrinsic beauty), here is another take on it with sed:
>
> --- 8< ----------------------------------------------------------------
> #!/bin/bash
>
> for b in *.xxx; do
>    c=`echo $b | sed -e s/^..//g` #change nr. of dots for different
>    mv $b $c                      #nr. of chars stripped
> done
> --- 8< ----------------------------------------------------------------
>
> Care has to be taken for whitespace and other nastinesses in the
> filename.

Thanks to all who have replied to my query!

Trying the script above returned:

/usr/local/bin/test.sh: line 4:  : command not found
/usr/local/bin/test.sh: line 5:  : command not found

Sed is of course on my system. 

Thanks again for any help...

Jeff




Reply to: