I want to seperate my data by time of day


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I want to seperate my data by time of day
# 1  
Old 01-26-2009
I want to seperate my data by time of day

Hi, I'm a newbie to unix. I have a txt file with my data, a list of events. Each event comes with a unix time. I want to seperate a months worth of events into those that occur during the day, and those at night. I have no clue how to go about this, please can someone push me in the right direction.

here is a sample of data
40000 1227874736
40000 1227874737
40010 1227874738
40004 1227874739
40008 1227874740
40005 1227874741
40005 1227874742
40001 1227874743
40006 1227874744
40008 1227874745
40002 1227874746
# 2  
Old 01-26-2009
Hi,
You can try something like this first. You can format the datestring so it is easy for You to sort and select from there, maybe redirecting it to a temporary file first


Code:
while read errno unixdate
do 
echo $errno $(date '+%Y-%m-%d-%H.%M.%S' -d @$unixdate)
done < logfile > logfile.tmp

Depending on Your version of date, it *may* not work..
Best regards
/Lakris
# 3  
Old 01-26-2009
Sorry, but I don't understand the code at all, can you explain it a bit?
# 4  
Old 01-26-2009
Hammer & Screwdriver What is here is simply a start to what you are going to do

your input file
Code:
> cat file148
40000 1227874736
40000 1227874737
40010 1227874738
40004 1227874739
40008 1227874740
40005 1227874741
40005 1227874742
40001 1227874743
40006 1227874744
40008 1227874745
40002 1227874746

your script to determine the date for each entry
it reads each line from the file called file148, and outputs the code and date
Code:
> cat fix148.sh
while read errno unixdate
  do 
  echo $errno $(date '+%Y-%m-%d-%H.%M.%S' -d @$unixdate)
  done < file148 > file148.new

run the script
Code:
> fix148.sh

look at the output
each line has that first error code, and the date
the date is in a format better suited to separate into smaller files by day
Code:
> cat file148.new
40000 2008-11-28-04.18.56
40000 2008-11-28-04.18.57
40010 2008-11-28-04.18.58
40004 2008-11-28-04.18.59
40008 2008-11-28-04.19.00
40005 2008-11-28-04.19.01
40005 2008-11-28-04.19.02
40001 2008-11-28-04.19.03
40006 2008-11-28-04.19.04
40008 2008-11-28-04.19.05
40002 2008-11-28-04.19.06

# 5  
Old 01-26-2009
Thank you both of you, I've understood your explanation fully. Now that it is in date format rather than unix time, how do I separate them into day/night ? Also, is the hour in the output in 24hr or 12hr notation? Thanks for everything
# 6  
Old 01-26-2009
Question

That should be 24 hour time.
About separating day/night... how do you define day/night?
is day >=06:00 and <18:00 ?
or do you split at 12:00 ? as in am/pm?
# 7  
Old 01-27-2009
I will define day from 06:00am to 18:00pm, and night the rest. But I will later use the sunrise and sunset time. So if possible could you explain it in a general form. My data set is a month long, is it possible to separate them all in one go, or will it be X y X M X D 06:00H etc for each day? Thank you
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get day of week from epoch time

Need assistance . Below code gives me the date but I wanted output as day of the week (wday) . Code: use Time::Local; my $time=timelocal(1,2,3,9,11,2013); $theTime = localtime($time); print "$theTime\n"; Result: Mon Dec 9 03:02:01 2013 Wanted output as only Mon (2 Replies)
Discussion started by: ajayram_arya
2 Replies

2. UNIX for Advanced & Expert Users

Need to get the time difference for all the transactions in a day

Hello Experts, I need to evaluate my API performance, so need a script to get the time difference for all the transaction that has gone through my application in a day. The challenge is the multi threaded logs, so I cant just get all the Telephone Numbers and check the entering and existing... (5 Replies)
Discussion started by: samjna
5 Replies

3. AIX

Time of Day Question

I have a question i need clarification. We had a problem on a p520 system and had to pull the battery on the service processor card. That did the trick and system booted. We forgot to set the time in the service processor before booting. Once AIX was booted we changed the date and time there. ... (1 Reply)
Discussion started by: ryan0911
1 Replies

4. Shell Programming and Scripting

How to? Every day, same time... script...

I manage to find and proces one script, now i need to automate this script for every day at the same time... (2 Replies)
Discussion started by: voltaza
2 Replies

5. Shell Programming and Scripting

value of variable based on time of the day

i would need some help in setting the value of a variable (TIME_NOW) depending on the time of the day ...e.g. if today's date is 12th April 2009 and if the current time is between midnight and 16:59:59 hrs then the TIME_NOW should be yesterday's date i.e. TIME_NOW=11 else if the current time... (3 Replies)
Discussion started by: zainravi
3 Replies

6. Shell Programming and Scripting

awk convert seconds to time of day

Does anyone know of a way to convert "seconds" to time of day in "hh:mm:ss" ? Trying to do in awk with strftime but with no luck. Thanks (2 Replies)
Discussion started by: timj123
2 Replies

7. Shell Programming and Scripting

UNIX -> send data as excel in seperate cells

Hi I have a data file in UNIX as follows. I need to send this file in Mail as excel format. but the problem i face is i get the data all in single cells per row. what can i do to get the data in seperate cells. File -> attachment.xls data data data data data1 data1 ... (1 Reply)
Discussion started by: vj8436
1 Replies

8. Shell Programming and Scripting

how to awk a data from seperate lines

Hi guys, i have a problem which im hoping you will be able to help me with. I have follwing output :- ------------------------------------------------------------------------------- NSTEP = 407000 TIME(PS) = 43059.000 TEMP(K) = 288.46 PRESS = 0.0 Etot = -2077.4322 ... (2 Replies)
Discussion started by: Mish_99
2 Replies

9. Shell Programming and Scripting

Need help to seperate data

Hello ALL, I really need help to grep data and store in particular format. I am struggling to write that script .Please help me to solve this problem otherwise i will loose my job... I have to compare 2 files and generate the staticts of the data. First file product.dat contains 2 column . ... (4 Replies)
Discussion started by: getdpg
4 Replies
Login or Register to Ask a Question