LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Insert Date timestamp from .gz files. (https://www.linuxquestions.org/questions/linux-newbie-8/insert-date-timestamp-from-gz-files-4175428985/)

liketheshell 09-25-2012 01:32 PM

Insert Date timestamp from .gz files.
 
Hello Friends,

I have an inquiry where i have a directory of .gz files.

rw-r--r-- 1 Wootie Wootie 175 Sep 2 00:30 bk.2012.09.01.gz
-rw-r--r-- 1 Wootie Wootie 20311 Sep 3 00:30 bk.2012.09.02.gz
-rw-r--r-- 1 Wootie Wootie 534140 Sep 4 01:00 bk.2012.09.03.gz

The files do not have timestamps in them and i'm trying to figure out a way to insert the associated timestamp to the correct file into one file.

So the output would be something as such from reading bk.2012.09.01.gz

Sep 2
83.60300,0/4750000,2459405781485463,83.603@0
83.60300,0/4750000,2459405781485463,83.603@0,

Sep 3

83.60300,0/4750000,2459405781485463,83.603@1
83.60300,0/4750000,2459405781485463,83.603@1

I have tried this but to no avail.

#!/bin/bash

cd ~tech/reports/production

TIMESTAMP=$(ls -l | grep -i bk.2012.09 |awk '{print $6,$7}')
FILE="/home/resource/public_html/reports/production/bk.2012.09*.gz"

while IFS= read -r line

do gunzip -c $line |grep -i alphamale > /tmp/test.xls

done <"$FILE"

Please assist,

Regards,

Liketheshell

unSpawn 09-25-2012 06:26 PM

Something like this?
Code:

SRCPATH="/home/resource/public_html/reports/production"
find $SRCPATH -type f -iname bk.\*.gz -printf "%f\n"| while read ITEM; do
 F=(${ITEM//./ }); M=$(/bin/date +"%b" --date="${F[2]}"); echo -en "${M} ${F[3]}\n\n"
 gunzip "${SRCPATH}/${ITEM}"; echo; done > "${SRCPATH}/output.txt"


liketheshell 09-25-2012 08:44 PM

Quote:

Originally Posted by unSpawn (Post 4789274)
Something like this?
Code:

SRCPATH="/home/resource/public_html/reports/production"
find $SRCPATH -type f -iname bk.\*.gz -printf "%f\n"| while read ITEM; do
 F=(${ITEM//./ }); M=$(/bin/date +"%b" --date="${F[2]}"); echo -en "${M} ${F[3]}\n\n"
 gunzip "${SRCPATH}/${ITEM}"; echo; done > "${SRCPATH}/output.txt"


====

Unspawn,

i will try your suggestion and many thanks for the feedback. The only inquiry i do have is the timestamp needs to come from the time the file(s) where created and not the current system time. I will give it a go though.

Many Thanks,

Alfred (Liketheshell)... :)


All times are GMT -5. The time now is 06:54 PM.