Need a file renaming facility

Amos Shapira amoss%HUJINIX.BITNET at cunyvm.cuny.edu
Mon May 9 04:00:19 AEST 1988


Chris Reimer (ctr at stride.com) writes:
>In article <3564 at fluke.COM> inc at tc.fluke.COM (Gary Benson) writes:
>>
>>    QT.1.r       QT.4.r           QT.A.r
>>    Qt.1.r.pre       QT.4.r.pre           QT.A.r.pre
>>
>>Now I want to rename all those ".pre" files to the same name without ".pre".
>
>Try:
>    foo% foreach i ( `ls *.pre  sed 's/.pre$//'` )
>    ? echo "Moving ${i}..."
>    ? mv ${i}.pre $i
>    ? end
>
>Obviously (I hope), this must be run under csh.  Enjoy!

      Could make it simpler, and much more importnt, faster.
    My suggestion is to use basename(1), like this:

    % foreach i (*.pre)
    ? echo Moving $i...
    ? mv $i `basename $i .pre`
    ? end

      basename(1) is under /usr/bin, so I'm not sure if it
    comes with SV systems. But you can write one for yourself.

      Maybe the forking of a new basename program for each
    file is slower than running one, a bit bigger, sed, but
    after the first time the basename program is loaded, it
    stays in memory, and so the rest should take much faster.
    Also basename is much simpler than sed.

      If you still want to use Chris's idea, be carefull to
    use /bin/ls, to prevent aliasing (here at HU, people like
    to alias ls to use the -F flag, which may break Chris's
    solution).

Have fun!
--Amos Shapira
The Hebrew University of Jerusalem, Israel.

==============================================================================
BITNET: amoss at hujinix.bitnet         CSnet: amoss%shum.huji.ac.il at relay.cs.net
UUCPnet: ucbvax!shum.huji.ac.il!amoss      Domain-Style: amoss at shum.huji.ac.il
==============================================================================

"Super users do it without asking for permission." - me



More information about the Comp.unix.questions mailing list