Ray Olszewski wrote:
> 
> > > In my case I need the first 8 characters and the
> > > last 4 (.xxx)
> >
> >--------------------------------------------------
> >example="long-filename.to.munge.txt"
> >echo ${example%${example#????????}}.${example##*.}
> >--------------------------------------------------
> 
> All the approaches suggested for this exercise assume that one 
> need not worry about generating a UNIQUE 8.3 filename from the 
> long filename. Is that assumption appropriate to Ben's real, 
> underlying problem? Or does it risk overwriting a file with a 
> later one 

OK, Ray, here's one off the top of my head.  I'm sure it 
can be improved, but it will do for a start.
-------------------------------------------------------------
#!/bin/bash
from="/home/ichi"  to="/tmp"
for i in `ls $from` ; do 
front=${i%.*} ; back=""
echo $i | grep "\." >/dev/null ; [ $? = 0 ] && back=.${i##*.}
[ ${#front} -gt 8 ] && front=${front%${front#????????}}
[ ${#back} -gt 4 ] && back=${back%${back#????}}
front=`echo $front | tr " ." "__"`
new=$front$back
for j in `ls $to` ; do
  case $j in $new) 
     echo "$new already exists.  Input new name."
     read new 
  esac
done
echo $new  ### YOUR OUTPUT ROUTINE GOES HERE ### 
done
--------------------------------------------------------------

I suppose somebody is going to tell that there is a built-in
command that does this automatically.  Ah, well.

Cheers,
Steven

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Reply via email to