Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename files 1

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
I can't get my head round this one :
I have several files on a remote server to rename daily.
files are in format cm99ddmmyy.tx and I want to rename them cm99ddmmyy (ie drop the tx)
rsh remserv1 mv /data/dfy/cm99*.tx /data/dfy/cm99?????? > /dev/null 2>&1

It'll be basename, I guess, but how ?
Any thoughts ?
TIA

Dickie Bird (:)-)))
 
(for file in /data/dfy/cm99*.tx ; do echo mv $file ${file%.tx}; done)
 
Thanks Ygor, you got me back on track !
I had to refine your idea for AIX -
rsh rserver 'for file in /data/dfy/cm*.tx ; do mv $file ${file%.tx}; done' >/dev/null 2>&1
I took out the echo and () - replaced as above.
I've never seen the % used in above construct - what's it doing?
Anyway - thanks again.


Dickie Bird (:)-)))
 
From 'man ksh' :-

${parameter%pattern}
${parameter%%pattern}
If the shell pattern matches the end of the
value of parameter, the value of parameter
with the matched part is deleted; otherwise
substitute the value of parameter. In the
former, the smallest matching pattern is
deleted; in the latter, the largest matching
pattern is deleted.

P.S. Sorry for any confusion - the echo and brackets were just a left-over from doing a syntax check before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top