Text Manipulation - Increment time/day
I have a file with approximately 16 million rows and need to insert date/time stamps for each row in 1 hour increments for an entire year and then starting over when a new value is in the first column.
ie. Code:
A,40,30 Code:
A,01/01/2017 01:00,40,30 |
If you use Linux, it's possible to use gawk time functions as well
eg: Code:
awk ' Format output as you wish Edit: you'll need another test if you want to go from 23:00 to 1:00 |
First of all, I'd stuff that data into a SQLite database file and do further manipulations with it that way.
Then, treating this file as the "database" that it in fact is, you'll need to write a short computer-program using some language other than "Bash scripting." |
After playing around a bit, I was able to use the following:
Code:
awk 'BEGIN |
Quote:
With this InFile ... Code:
2011 apple Code:
awk '{if ($1!=save) counter++; save=$1; Code:
1 2011 apple . |
That's good info Daniel and I'm going to take a look at that to see if I can figure out how to adjust. However my desired outcome is the following in your example:
Code:
1 2011 apple |
Quote:
So you have to test $1 each time with a variable value, if changed reset hour to 1 |
Quote:
|
It sounds correct, post code if you're stuck
|
Quote:
With this InFile ... Code:
2011 apple Code:
awk '{if ($1!=save) j=0; save=$1; j++ Code:
1 2011 apple . |
I appreciate you forcing me to understand it and figure it out Daniel...though frustrating, i'm sure i'll be better off for it. Anyway I think i understand what your code is doing by checking if $1 does not equal save as well as saving the $1 value and finally incrementing the value for j which is initially set at 0. It seems that the mktime and strftime are throwing me off now (perhaps due to lack of understanding). I mangled together the following code with the included errors:
Code:
awk 'BEGIN {FS=OFS=",";hour=1;if ($1!=u) timestamp=mktime("2017 01 01 00 00 00");u=$1;(strftime("%D %R", timestamp + hour++ * 60 * 60))}{print $1,(strftime("%D %R", timestamp)),$2;}' input.csv > output.csv |
Post withdrawn. Advice was wrong.
|
I don't logically see the need for them either, removed them (from both strftime instances) but no change.
|
oh wait, i think i need to install gawk or something like that...i'm pretty sure i had this on my system at work and that's how i addressed it
|
Quote:
awk syntax is like: condition {action} so: Code:
awk ' $1 != u: condition if condtion is true then next block: {hour=1;u=$1} and following block is executed without condition |
All times are GMT -5. The time now is 04:53 PM. |