Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
bash script to increment a digit in filename

Hi guys,

Can someone help me out with this:

I have a directory with files like the following,
GHost++ 2010-03-14 04-01 DotaCash RD us_ca LC #7 (44m19s).w3g
GHost++ 2010-03-14 04-06 DotaCash AP us_ca LC #8 (42m24s).w3g
GHost++ 2010-03-14 04-07 DotaCash AR us_ca LC #10 (08m23s).w3g
GHost++ 2010-03-14 04-13 DotaCash AR us_ca LC #8 (48m17s).w3g
GHost++ 2010-03-14 04-15 DotaCash RD us_ca LC #9 (45m17s).w3g

I would like to know how to add to the hour part of the filename for all the files in that direction. In this particular example, add 3 to 04, so it becomes 07.

end result would be something like this.
GHost++ 2010-03-14 07-01 DotaCash RD us_ca LC #7 (44m19s).w3g
GHost++ 2010-03-14 07-06 DotaCash AP us_ca LC #8 (42m24s).w3g
GHost++ 2010-03-14 07-07 DotaCash AR us_ca LC #10 (08m23s).w3g
GHost++ 2010-03-14 07-13 DotaCash AR us_ca LC #8 (48m17s).w3g
GHost++ 2010-03-14 07-15 DotaCash RD us_ca LC #9 (45m17s).w3g

Any help is greatly appreciated.

Thanks.,
Sponsored Links
    #2  
Old 03-14-2010
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 8,511
Thanks: 67
Thanked 403 Times in 392 Posts

Code:
ls GHost++ 2010-03-14 04-* |
awk -F'[ -1]'  '{ old=$0; $5+=3; system( sprintf("mv %s %s",old, $0) ) } '

Try nawk on Solaris
Sponsored Links
    #3  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi thanks for the quick response.
It did not work...



Code:
 
ls GHost++\ `date +%Y-%m-%d`* | awk -F'[ -1]'  '{ old=$0; $5+=3; system( sprintf("mv %s %s",old, $0) ) } '
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory
mv: target `LC' is not a directory



---------- Post updated at 07:52 AM ---------- Previous update was at 07:27 AM ----------

I am not sure if this would make it easier, but basically I want to add 3 hours to the date stamp in the file name.
    #4  
Old 03-14-2010
thegeek thegeek is offline Forum Advisor  
Registered User
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 1,090
Thanks: 13
Thanked 37 Times in 35 Posts
rename 's/([^\s]+\s){2}(\d+)/$1. " " . ($2+3)/e' GHost++*


Code:
ls
GHost++ 2010-03-14 04-01 DotaCash RD us_ca LC #7 (44m19s).w3g
GHost++ 2010-03-14 04-06 DotaCash AP us_ca LC #8 (42m24s).w3g
GHost++ 2010-03-14 04-07 DotaCash AR us_ca LC #10 (08m23s).w3g
GHost++ 2010-03-14 04-13 DotaCash AR us_ca LC #8 (48m17s).w3g
GHost++ 2010-03-14 04-15 DotaCash RD us_ca LC #9 (45m17s).w3g

19:55:12 : t :rename 's/([^\s]+\s){2}(\d+)/$1. " " . ($2+3)/e' GHost++*
19:55:34 : t :ls
2010-03-14  7-01 DotaCash RD us_ca LC #7 (44m19s).w3g
2010-03-14  7-06 DotaCash AP us_ca LC #8 (42m24s).w3g
2010-03-14  7-07 DotaCash AR us_ca LC #10 (08m23s).w3g
2010-03-14  7-13 DotaCash AR us_ca LC #8 (48m17s).w3g
2010-03-14  7-15 DotaCash RD us_ca LC #9 (45m17s).w3g

Sponsored Links
    #5  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks.

Getting closer, however, the 04 was replaced with just 3, that will not work due to the change in format of filename
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Increment date in script jyothi_wipro Shell Programming and Scripting 4 12-22-2009 05:29 AM
[BASH] Remove Link from Filename Syekiya Shell Programming and Scripting 6 04-20-2009 11:12 AM
How to convert a 2 digit to 4 digit jisha Shell Programming and Scripting 6 04-23-2008 06:38 AM
Shell Script To increment Date*HElp*** niceboykunal123 Shell Programming and Scripting 1 04-23-2008 01:05 AM
Replace one digit by two digit using sed Jae Shell Programming and Scripting 5 04-18-2008 12:32 AM



All times are GMT -4. The time now is 03:25 AM.