Results 1 to 3 of 3
All,
I have searched for a solution to this and tried numerous things, but I am limited on my abilities with grep/awk/shell scripting etc and spent too many hours already. ...
- 05-05-2011 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 5
converting epoch in a file name to human readable date/time
All,
I have searched for a solution to this and tried numerous things, but I am limited on my abilities with grep/awk/shell scripting etc and spent too many hours already. Maybe someone smarter than I can easily help me with a quick one-liner, perl/python script, etc...?
I have log files that everyday are downloaded from my webserver in the format:
xxxxxxxxxx is a 10 digit epoch time.Code:samplesite.com.xxxxxxxxxxx.gz
I am trying to figure out a way in batch to:
1. find all of exisiting files containing the pattern (after the first run it will only be one a day)
2. Isolate the epoch string
3. convert the epoch string to human readable date/time
4. rename the original file as samplesite.com.mmddYYYY.gz
Thanks so much!
- 05-06-2011 #2
Hi sinusoid
About step 1: Are you downloading these backup files manually or should this also happen automatically?
For step 2, 3 and 4 I would do something like this ...
Greetings from SwitzerlandCode:#!/bin/bash for i in *.gz do # getting length of timestamp (if 10 = timestamp - if not, already converted file) TSLENGHT=$(echo $i | cut -d'.' -f3 | awk '{print length}') if [ $TSLENGHT == 10 ]; then # cutting timestamp out of filename FILETIMESTAMP=$(echo $i | cut -d'.' -f3) # getting correct date format FILEDATE=$(date -d "1970-01-01 $FILETIMESTAMP sec" "+%d%m%Y") # renaming mv $i "samplesite.com.$FILEDATE.gz" fi done
FabTK
//edit: tested and worksLast edited by fabtk; 05-06-2011 at 09:44 AM.
- 05-06-2011 #3Just Joined!
- Join Date
- Mar 2010
- Posts
- 5
FabTK --- this is FANTASTIC!
Thank you SO much!


Reply With Quote