Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!adm!amoss%HUJINIX.BITNET@cunyvm.cuny.edu From: amoss%HUJINIX.BITNET@cunyvm.cuny.edu (Amos Shapira) Newsgroups: comp.unix.questions Subject: Re: Need a file renaming facility Message-ID: <13840@brl-adm.ARPA> Date: 8 May 88 18:00:19 GMT Sender: news@brl-adm.ARPA Lines: 48 Chris Reimer (ctr@stride.com) writes: >In article <3564@fluke.COM> inc@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@hujinix.bitnet CSnet: amoss%shum.huji.ac.il@relay.cs.net UUCPnet: ucbvax!shum.huji.ac.il!amoss Domain-Style: amoss@shum.huji.ac.il ============================================================================== "Super users do it without asking for permission." - me