![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 | Thread Starter | Forum | Replies | Last Post |
| Processing a log file based on date/time input and the date/time on the log file | primp | Shell Programming and Scripting | 4 | 03-16-2008 08:23 AM |
| find formatted filename with date time | dpath2o | UNIX for Advanced & Expert Users | 6 | 02-05-2008 08:20 PM |
| insert filename into file using SED (or AWK) | USER#5 | Shell Programming and Scripting | 2 | 08-06-2006 07:08 PM |
| Insert Time and Date Stamp | aajmani | Shell Programming and Scripting | 1 | 10-13-2005 12:15 PM |
| Renaming files to have date/time in filename | wayneb | UNIX for Dummies Questions & Answers | 5 | 01-19-2005 07:49 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Insert date/time within a filename
Hi Guys,
I need to script the renaming of files as followins: files: firstjd secondjo thirdjv My script needs to insert the date/time infront of the last 2 characters of the filenames above, any ideas greatly received the letters before the last 2 characters could change, I'm only interested in inserting date/time in front of the last 2 characters, whatever they maybe. Many thanks |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Check this out.
Code:
#! /bin/sh
for FILE in firstjd secondjo thirdjv
do
NAME_LEN=${#FILE}
FILE_END=${FILE:$NAME_LEN-2:$NAME_LEN}
FILE_START=${FILE%$FILE_END}
NEW_NAME=$FILE_START$(date +%s)$FILE_END
mv $FILE $NEW_NAME
done
vino Last edited by vino; 11-07-2005 at 05:45 AM. |
|
#3
|
|||
|
|||
|
Thanks for that Vino, BUT
I get the following error: `NEW_NAME=$FILE_START$' unexpected any ideas ? thanks again |
|
#4
|
||||
|
||||
|
Code:
#!/bin/ksh
for iter in firstjd secondjo thirdjv
do
_time=$(date +%Y%m%d-%H%M%S)
new=$(echo ${iter} | sed "s/\(.*\)\(..\)/\1${_time}\2/")
echo "old->[${iter}] new->[${new}]"
done
|
|
#5
|
||||
|
||||
|
Quote:
Code:
NEW_NAME=${FILE_START}$(date +%s)${FILE_END}
Last edited by vino; 11-07-2005 at 07:32 AM. |
|
#6
|
||||
|
||||
|
Quote:
I was trying to avoid an external call. Cheers' ! |
|
#7
|
||||
|
||||
|
here's a "pure" ksh:
Code:
#!/bin/ksh
for iter in firstjd secondjo thirdjv
do
_time=$(date +%Y%m%d-%H%M%S)
root="${iter%%??}"
suf="${iter##${root}}"
echo "old->[${iter}] new->[${root}${_time}${suf}]"
done
|
||||
| Google The UNIX and Linux Forums |