|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
![]() |
|
|
Search this Thread |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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 | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |