UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 16th, 2012, 03:32 PM
rehlow rehlow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 rehlow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 38 sec
Reputation Power: 0
Renaming a file when I only know part of the filename

Hi,

I am a UNIX newbie. I need help renaming a file when I only know part of the filename. I know the file will look like:

My_report_"YYYY_MM_DD_timestamp".csv

I get a copy of the report each day with the timestamp of when the file was created. I know it is created each day, but the timestamp can vary. I want to FTP the file to another directory and remove the timestamp portion so the resulting file would look like

My_report_"YYYY_MM_DD".csv

I tried setting up some variables for date, but when I try to use them I get

My_report_date not found instead of it translating to the variable I setup as

My_report_2012_10_16

Please help.

Thanks,
~Rehlow

Reply With Quote
  #2  
Old October 16th, 2012, 04:58 PM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
What about something like

Code:
STAMP=$(date +"%Y-%m-%d")
mv /source/folder/My_report* /new/folder/My_report_$STAMP.csv



?
__________________
The number for UK Emergencies is changing, the new number is 0118 999 881 999 119 7253

"For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
- George Orwell, 1984

Reply With Quote
  #3  
Old October 17th, 2012, 03:41 PM
rehlow rehlow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 rehlow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 38 sec
Reputation Power: 0
Quote:
Originally Posted by badger_fruit
What about something like

Code:
STAMP=$(date +"%Y-%m-%d")
mv /source/folder/My_report* /new/folder/My_report_$STAMP.csv



?


That worked. Thanks. With my prior attempt I was declaring my variable incorrectly (that's what I get for borrowing someone else's code).

Thanks again,
~Rehlow

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Renaming a file when I only know part of the filename

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap