|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find & Replace
Hi I am looking to rename the contents of this dir, each one with a new timestamp, interval of a second for each so it the existing format is on lhs and what I want is to rename each of these to what is on rhs..hopefully it nake sense Code:
CDR.20060505.150006.gb CDR.20121211.191500.gb CDR.20060505.150109.gb CDR.20121211.191501.gb CDR.20060505.150216.gb CDR.20121211.191502.gb CDR.20060505.150308.gb CDR.20121211.191503.gb Hopefully this makes sense. I know I need to utilise a sed command in conjunction with some sort of loop Last edited by rob171171; 12-11-2012 at 02:20 PM.. Reason: more detail |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
How about? Code:
for file in CDR*.gb
do
echo "mv $file CDR.$( date +'%Y%m%d.%H%M%S' ).gb"
sleep 1
doneNote: remove echo if the result is OK, replace like below:- Code:
mv "$file" "CDR.$( date +'%Y%m%d.%H%M%S' ).gb" |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
rob171171 (12-11-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
sed is not the be-all and end-all of text. I'm not sure what I'd even use it for here since you're just replacing everything with everything... Code:
read YYYYMMDD HH MM SS <<EOF
`date '+%Y%m%d %H %M %S'`
EOF
[ "${HH:0:1}" = "0" ] && HH="${HH:1}"
[ "${MM:0:1}" = "0" ] && MM="${MM:1}"
[ "${SS:0:1}" = "0" ] && SS="${SS:1}"
for FILE in *.gb
do
echo mv "$FILE" "$YYYY-$HH$MM$SS.gb"
let SS=SS+1
[ "$SS" -gt 59 ] && SS=0 && let MM=MM+1
[ "$MM" -gt 59 ] && MM=0 && let HH=HH+1
[ "$HH" -gt 23 ] && HH=0
doneRemove the echo once you've tested and are sure it does what you want. bipinajith's code is much simpler But if you have 500 files, will take 8 minutes...
|
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
rob171171 (12-11-2012) | ||
|
#4
|
|||
|
|||
|
Thank you so much, that 1s 100% exactly what i was after. My approach was much different tyring to use sed and more complex solutions
Thanks again ---------- Post updated at 02:40 PM ---------- Previous update was at 02:39 PM ---------- Thank you Corona688 for your response,. You are correct in that |
| 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 |
| Find & Replace string in multiple files & folders using perl | Zaheer.mic | Shell Programming and Scripting | 0 | 11-04-2009 12:08 PM |
| find & replace with user input | mike909 | Shell Programming and Scripting | 3 | 10-06-2009 02:36 PM |
| Find & Replace string in multiple files & folders | karthikn7974 | Shell Programming and Scripting | 4 | 04-29-2009 07:30 PM |
| find & incremental replace? | treadwm | Shell Programming and Scripting | 2 | 04-21-2009 08:41 PM |
| Find & Replace | gagansharma | Shell Programming and Scripting | 3 | 11-27-2001 03:17 PM |
|
|