Your Ad Here

Jumat, 15 Januari 2016

Unix Tip: CHANGE THE SUFFIX

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

UNIX GURU UNIVERSE
UNIX HOT TIP

Unix Tip 3263 - January 15, 2016

http://www.ugu.com/sui/ugu/show?tip.today

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


CHANGE THE SUFFIX

If you want to change the suffix of
multiple files, you can't do:

% mv *.abc *.def

However the following shell script
can be used to do the required
opperation:

***

Change all *.abc file to *.def the
following shell script would work:

#!/bin/sh
for f in *.abc; do
mv $f `basename $f .abc`.def
done

How it works:

for f in *.abc; do

Set up a look for all files ending
in .abc, and each time around setup
$f as the filename

mv $f `basename $f.abc`.def

`basename $f .abc` takes the filename
in $f and removes any trailing occurences
of .abc, we then append .def to the result
and the resulting command becomes
"mv file.abc file.def"

done

Ends the "for" loop above.

Under "csh" or "tcsh" a similar thing could be done with:

foreach f in ( *.abc )
mv $f `basename $f .abc`.def
end



This tip generously supported by: pwain@liberate.com



--------------------------------------------------------------------------
To Subscribe: http://www.ugu.com/sui/ugu/show?tip.subscribe
To Unsubscribe: http://www.ugu.com/sui/ugu/show?tip.unsubscribe
To Submit A Tip: http://www.ugu.com/sui/ugu/show?tip.today

==========================================================================
DISCLAIMER: All UNIX HOT TIPS ARE OWNED BY THE UNIX GURU UNIVERSE AND ARE
NOT TO BE SOLD, PRINTED OR USED WITHOUT THE WRITTEN CONSENT OF THE UNIX
GURU UNIVERSE. ALL TIPS ARE "USE AT YOUR OWN RISK". UGU ADVISES THAT
ALL TIPS BE TESTED IN A NON-PRODUCTION DEVELOPMENT ENVIRONMENT FIRST.

Unix Guru Universe - www.ugu.com - tips@ugu.com - Copyright 1994-2001
==========================================================================

Tidak ada komentar:

Posting Komentar

Your Ad Here
Free Automatic Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink Free Auto Backlink