LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2012, 02:32 PM   #1
liketheshell
LQ Newbie
 
Registered: Sep 2012
Posts: 18

Rep: Reputation: Disabled
Question 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
 
Old 09-25-2012, 07:26 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
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"
 
Old 09-25-2012, 09:44 PM   #3
liketheshell
LQ Newbie
 
Registered: Sep 2012
Posts: 18

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by unSpawn View Post
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)...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql insert only if the values are different than the max timestamp secretlydead Programming 8 05-21-2012 08:04 PM
[SOLVED] how to put date and timestamp to bash_history ? dlugasx Linux - General 4 10-28-2009 04:59 PM
How to get date from unix timestamp ruj.sabya Linux - General 9 03-22-2007 06:59 PM
Insert date and timestamp Into File name petenyce Linux - Newbie 9 10-13-2005 01:16 PM
Converting the date (not timestamp) mpgram Programming 2 04-18-2004 04:56 PM


All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration