[Wlug] Bash help
Thu, 18 Jul 2002 00:01:09 -0400 (EDT)
for i in * ; do
mv $i `echo $i | sed 's/\(.*\)..\.\(.*\)/\1.\2/'`
Should do the trick... It moves each file to the original filename, minus
the two characters before the last .
As far as a book to get, _Learning the bash Shell, 2nd Edition_, published
by o'reilly. Also likely useful _sed & awk, 2nd Edition_, also published
by o'reilly. The sed book will translate that example of leaning
On Wed, 17 Jul 2002, Tim Trachimowicz wrote:
> Hey folks!
> I have a bunch of files on a server that are in the
> format "filename_x.dat" and I need to rename them "filename.dat", i.e.
> strip to last two characters off the filename while maintaining the
> If it wasn't for the fact that I have about 400 files in multiple
> directories, I'd do it by hand. However, it's of a somewhat urgent
> nature - hence this slightly off-topic cry for help! =)
> I'm pretty sure there's a way to do it via a shell script (I use bash) -
> the only problem being that I've never written one before. Can anyone
> point me to a faq/tutorial/website that might explain the process? If
> it's a trivial task, anyone care to take a stab? Google gave me a few
> leads, but most aren't helping a lot.
> Any help is appreciated! Thanks!
> Wlug mailing list