Time validation in a csv file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Time validation in a csv file
# 1  
Old 02-26-2009
Error Time validation in a csv file

Hi,

Im having a hard time in creating a script with the following conditions below. I have a csv file generated which is updated every 5 mins and it contains a timestamp in it. for example:

time data
00:00 1
00:05 0
00:10 6
00:15 3

however, there is a time that the csv file is not updated this means that a certain line will be skipped.

time data
00:00 1
00:10 7
00:25 8

do any of you guys have an idea on how to validate the data in such a way that if a time is skipped, it will automaticall fill up the missing time?

what i have in mind is that it will return the following:

time data
00:00 1
00:05 0 -turns the missing data into zero value
00:10 7
00:15 0
00:20 0
00:25 8

what i am trying right now is to create a file that contains the correct time incrementation (00:00 / 00:05 / 00:10 .. so on), and then compare the two, however, i dont know where to start...

Thank you again! Smilie
# 2  
Old 02-26-2009
Will the data be guaranteed to always be in spot-on 5 minute intervals unless skipped? A minute less or extra here and there would make it much more difficult to check.
# 3  
Old 02-26-2009
Code:
nawk '
function LZ ( X )
{
        if ( length(X) < 2 )
                return "0"X
        else
                return X
}

BEGIN { for (i=0; i<=23; i++ )
          for (j=0; j<=55; j += 5 )
             _[LZ(i),LZ(j)]=0
        }
/:/ { _[substr($1,1,2),substr($1,4,2)]=$2 }

END { for (i=0; i<=23; i++ )
          for (j=0; j<=55; j += 5 )
             print LZ(i)":"LZ(j)" "_[LZ(i),LZ(j)]
        }

'

This uses function LZ (leading zero) to pad the time as required.
BEGIN statement initializes array to 0
Read records with time (containing Smilie
END prints out array using LZ function as well.
# 4  
Old 02-26-2009
actually, the timestamp does not exactly start at 5 mins.
for example:

time data
00:06 8
00:12 2
# 5  
Old 02-26-2009
So what exactly do you want to see?
Quote:
time data
00:00 0
00:05 0
00:06 8
00:10 0
00:12 2
i.e. Do you still need 5 min increments zeroized?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add current time stamp column in existing csv file

Hi , I want to add a new column 'current_time stamp' in my existing csv file with current time stamp for all the records.I tried something this but this is printing 0 with date & time and printed date one line above header.Please help awk -F "," 'BEGIN{ OFS="," } {$6=system("date... (5 Replies)
Discussion started by: netdbaind
5 Replies

2. Shell Programming and Scripting

Get first and last time entries for a given date in CSV file

CSV date sorted file has multiple entries for most dates. Need to eliminate all but the first and last entries of each date, being the start and end times for that day. 2009-11-20,23:57:46 2009-11-20,23:58:46 2009-11-20,23:59:46 2009-11-21,00:00:45 2009-11-21,00:01:46 2009-11-21,00:02:45... (2 Replies)
Discussion started by: mdennis6
2 Replies

3. Shell Programming and Scripting

awk work with time change in csv file

Hi, i have csv input file looks like below 3rd field is date and time field i want to change it with user supplied date and time says year=2011 month=09 day=05 hour=11 count=2 when count is say 10 then first ten records should pick and it should increment the... (2 Replies)
Discussion started by: raghavendra.nsn
2 Replies

4. Shell Programming and Scripting

Strip time from CSV File?

Hi, I've been trying (and failing miserably) all morning to strip from a CSV file the time from it. Can somebody point me in the right direction on how to do this using sed or awk? The file looks like: "James","07/20/2009-14:40:11" "Steve","08/06/2006-02:34:37"... (5 Replies)
Discussion started by: nmuntz
5 Replies

5. Shell Programming and Scripting

awk date and time validation

How can i validate if user inserted date and optionly a time is vaild but in awk scripting? (18 Replies)
Discussion started by: tal
18 Replies

6. Shell Programming and Scripting

shell script data & time validation

How to validate a date and optionly a time in shell scripting when i get the date and time as pararmeters that sent out with the call of the file? (in my case sh union.sh `first parameter ,second parameter...` (4 Replies)
Discussion started by: tal
4 Replies

7. Shell Programming and Scripting

CSV file parsing and validation

I have a CSV file that needs to through two seperate processes (in the end there will be 2 files (Dload.unl and Tload.unl and we'll say the input file name is mass.csv). I have a processfile() function that will call the process Dload funtion. In Dload I want to read mass.csv into Dload and then... (1 Reply)
Discussion started by: dolo21taf
1 Replies

8. Shell Programming and Scripting

validation of data using filter (awk or other that works...) in csv files

Hello People I have the following file.csv: date,string,float,number,boolean 20080303,abc,1.5,123,Y 20080304,abc,1.2,345,N 20080229,nvh,1.4,098,Y 20080319,ugy,1.9,586,N 20080315,gyh,2.4,345,Y 20080316,erf,3.1,932,N I need to filter the date field where I have a data bigger than I... (1 Reply)
Discussion started by: Rafael.Buria
1 Replies

9. UNIX for Dummies Questions & Answers

How Can I Do Time Validation in UNIX

I am very new to scripting in UNIX and in need of help. I am creating a program that will check a file that has a target time in the form of HH:MM:SS before another program can begin executing. The file with the target time will only have that target time in it and nothing else. Is there any... (4 Replies)
Discussion started by: mosammey
4 Replies

10. Shell Programming and Scripting

Time Validation in UNIX?

I am very new to scripting in UNIX and in need of help. I am creating a program that will check a file that has a target time in the form of HH:MM:SS before another program can begin executing. The file with the target time will only have that target time in it and nothing else. Is there any way... (1 Reply)
Discussion started by: mosammey
1 Replies
Login or Register to Ask a Question