*BSD News Article 42808


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msunews!uwm.edu!news.moneng.mei.com!howland.reston.ans.net!lamarck.sura.net!hookup!news.mathworks.com!uunet!ulowell.uml.edu!vtc.tacom.army.mil!news1.oakland.edu!news
From: "Calvin (Eric) Vette" <calvin@axe.ut.wayne.edu>
Newsgroups: comp.unix.bsd
Subject: Re: Newbie Question: mv *.t *.txt ????
Date: 23 Feb 1995 22:57:26 GMT
Organization: Oakland University, Rochester, Michigan, U.S.A.
Lines: 31
Message-ID: <3ij3sm$e6b@oak.oakland.edu>
References: <D41nyo.Mon@ritz.mordor.com> <3huiti$4lr@dagny.galt.com> <3i841g$48b@csugrad.cs.vt.edu>
NNTP-Posting-Host: axe.cit.wayne.edu

jaitken@csugrad.cs.vt.edu (Jeff Aitken) wrote:
>
> : Hany Nagib (hany@ritz.mordor.com) wrote:
> : : I know this must be a very simple question, but it's not in the FAQ.
> : : "mv" looks like it works exactly like "rename" in DOS, except when using 
> : : wild card. For example if I wanted to rename all my .t files to .txt, I 
> : : expect "mv *.t *.txt" to work .. but it doesn't. Why ? And how do I 
> : : accomplish this in BSD unix ?
> 
> This works in {t}csh:
> 
> foreach file ( *.t )
> foreach? mv $file `basename $file .t`.txt
> foreach? end
> 
> -- 
> Jeff Aitken
> jaitken@vt.edu
> 

While the basename example is more systematic, you can also try

foreach file ( *.t )
foreach? mv $file $file:r.txt
foreach? end

The :r refers to the root filename. It's shorter than the
basename example, which is why I use it over basename.

calvin
calvin@axe.ut.wayne.edu