Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Split large file into 24 small files on one hour basis Post 303036436 by Neo on Wednesday 26th of June 2019 07:09:24 AM
Old 06-26-2019
Actually, you do not even need to convert to a unix timestamp in PHP, you can use your formatted time string directly:

For example, I just tested your example data with your formatted time :

Code:
<?php
echo  date(h,"2019-05-20 09:55:39.945");

06

No need to convert to a unix timestamp.

Untested, but close:

Code:
<?php
$data = file_get_contents('mydata.txt');
foreach ($data as $entry) {
    $my_time_stuff = explode(' ', $entry);
    $formatted_time = $my_time_stuff[0] . ' ' . $my_time_stuff[1];
    $hour = date(h, $formatted_time);
    $file = 'myfilename' . $hour . '.txt';
    file_put_contents($file, $entry, FILE_APPEND | LOCK_EX);
}

Hope this PHP example helps.

If you want it to be "harder to read" and short:

Code:
<?php
$data = file_get_contents('mydata.txt');
foreach ($data as $entry) {
    $m= explode(' ', $entry);
    file_put_contents('myfilename' . date(h, $m[0] . ' ' . $m[1]) . '.txt', $entry, FILE_APPEND | LOCK_EX);
}

I prefer the long, easy to read, more-or-less self-documenting (first) version.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting large file into small files

Hi, I need to split a large file into small files based on a string. At different palces in the large I have the string ^Job. I need to split the file into different files starting from ^Job to the last character before the next ^Job. Also all the small files should be automatically named.... (4 Replies)
Discussion started by: dncs
4 Replies

2. Shell Programming and Scripting

Split a file into 16 small files

Hi I want to split a file that has 'n' number of records into 16 small files. Can some one suggest me how to do this using Unix script? Thanks rrkk (10 Replies)
Discussion started by: rrkks
10 Replies

3. Shell Programming and Scripting

Split large file and add header and footer to each small files

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (7 Replies)
Discussion started by: ashish4422
7 Replies

4. Shell Programming and Scripting

script to splite large file to number of small files

Dear All, Could you please help me to split a file contain around 240,000,000 line to 4 files all equally likely , note that we need to maintain that the end of each file should started by start flage (MSISDN) and ended by end flag (End), also the number of the line between the... (10 Replies)
Discussion started by: ahmed.gad
10 Replies

5. Shell Programming and Scripting

Split large zone file dump into multiple files

I have a large zone file dump that consists of ; DNS record for the adomain.com domain data1 data2 data3 data4 data5 CRLF CRLF CRLF ; DNS record for the anotherdomain.com domain data1 data2 data3 data4 data5 data6 CRLF (7 Replies)
Discussion started by: Bluemerlin
7 Replies

6. Shell Programming and Scripting

Split a large array into small chunks

Hi, I need to split a large array "@sharedArray" into 10 small arrays. The arrays should be like @sharedArray1,@sharedArray2,@sharedArray3...so on.. Can anyone help me with the logic to do so :(:confused: (6 Replies)
Discussion started by: rkrish
6 Replies

7. Shell Programming and Scripting

How to split this txt file into small files?

Dear shell experts, I would like to spilt a txt file into small ones. However, I did not know how to program use shell. If someone could help, it is greatly appreciated! Specifically, I supposed there is file named A.txt. The content of the file likes this: Subject run condtion ACC time... (3 Replies)
Discussion started by: psychmyluo
3 Replies

8. Shell Programming and Scripting

Breaking large file into small files

Dear all, I have huge txt file with the input files for some setup_code. However for running my setup_code, I require txt files with maximum of 1000 input files Please help me in suggesting way to break down this big txt file to small txt file of 1000 entries only. thanks and Greetings, Emily (12 Replies)
Discussion started by: emily
12 Replies

9. UNIX for Beginners Questions & Answers

Split large file into smaller files without disturbing the entry chunks

Dears, Need you help with the below file manipulation. I want to split the file into 8 smaller files but without cutting/disturbing the entries (meaning every small file should start with a entry and end with an empty line). It will be helpful if you can provide a one liner command for this... (12 Replies)
Discussion started by: Kamesh G
12 Replies

10. Shell Programming and Scripting

Split large xml into mutiple files and with header and footer in file

Split large xml into mutiple files and with header and footer in file tried below it splits unevenly and also i need help in adding header and footer command : csplit -s -k -f my_XML_split.xml extrfile.xml "/<Document>/" {1} sample xml <?xml version="1.0" encoding="UTF-8"?><Recipient>... (36 Replies)
Discussion started by: karthik
36 Replies
Scheduler Implementation API(3) 			 globus scheduler event generator			   Scheduler Implementation API(3)

NAME
Scheduler Implementation API - Enumerations enum globus_scheduler_event_generator_error_t { GLOBUS_SEG_ERROR_TYPE_NULL = 1024, GLOBUS_SEG_ERROR_TYPE_ALREADY_SET, GLOBUS_SEG_ERROR_TYPE_INVALID_MODULE, GLOBUS_SEG_ERROR_TYPE_INVALID_FORMAT, GLOBUS_SEG_ERROR_TYPE_OUT_OF_MEMORY, GLOBUS_SEG_ERROR_TYPE_LOADING_MODULE } Functions globus_result_t globus_scheduler_event (const char *format,...) globus_result_t globus_scheduler_event_pending (time_t timestamp, const char *jobid) globus_result_t globus_scheduler_event_active (time_t timestamp, const char *jobid) globus_result_t globus_scheduler_event_failed (time_t timestamp, const char *jobid, int failure_code) globus_result_t globus_scheduler_event_done (time_t timestamp, const char *jobid, int exit_code) globus_result_t globus_scheduler_event_generator_get_timestamp (time_t *timestamp) Detailed Description Scheduler-specific SEG module implementations use this API to issue events to the Job State Monitor. Events occur whenever a job is placed in the scheduler's queue (PENDING), begins execution (ACTIVE), terminates successfully (DONE), or ends abnormally (FAILED). A SEG module should register an event with the Globus event driver (most likely using either the Globus Callback or Globus XIO interfaces) in its activation function and then return. All events should be triggered from callbacks. When the SEG detects that it should terminate, it will deactivate the SEG module it started. The SEG module should wait for any outstanding callbacks to subside and before returning from its deactivation function to ensure that all events will be properly dispatched. After deactivation is complete, the SEG will unload the shared module and terminate. Enumeration Type Documentation enum globus_scheduler_event_generator_error_t Error types used by the SEG. Enumerator: GLOBUS_SEG_ERROR_TYPE_NULL NULL Parameter. GLOBUS_SEG_ERROR_TYPE_ALREADY_SET Already called a one-time function. GLOBUS_SEG_ERROR_TYPE_INVALID_MODULE Shared module missing descriptor. GLOBUS_SEG_ERROR_TYPE_INVALID_FORMAT Invalid printf format for SEG protocol message. GLOBUS_SEG_ERROR_TYPE_OUT_OF_MEMORY Out of memory. GLOBUS_SEG_ERROR_TYPE_LOADING_MODULE Unable to load scheduler module. Function Documentation globus_result_t globus_scheduler_event (const char *format, ...) Send an arbitrary SEG notification. Parameters: format Printf-style format of the SEG notification message ... Varargs which will be interpreted as per format. Return values: GLOBUS_SUCCESS Scheduler message sent or queued. GLOBUS_SEG_ERROR_NULL Null format. GLOBUS_SEG_ERROR_INVALID_FORMAT Unable to determine length of formatted string. globus_result_t globus_scheduler_event_pending (time_ttimestamp, const char *jobid) Send a job pending event to the JobSchedulerMonitor implementation. Parameters: timestamp Timestamp to use for the event. If set to 0, the time which this function was called is used. jobid String indicating the scheduler-specific name of the job. Return values: GLOBUS_SUCCESS Scheduler message sent or queued. GLOBUS_SEG_ERROR_NULL Null jobid. GLOBUS_SEG_ERROR_INVALID_FORMAT Unable to determine length of formatted string. globus_result_t globus_scheduler_event_active (time_ttimestamp, const char *jobid) Send a job active event to the JobSchedulerMonitor implementation. Parameters: timestamp Timestamp to use for the event. If set to 0, the time which this function was called is used. jobid String indicating the scheduler-specific name of the job. Return values: GLOBUS_SUCCESS Scheduler message sent or queued. GLOBUS_SEG_ERROR_NULL Null jobid. GLOBUS_SEG_ERROR_INVALID_FORMAT Unable to determine length of formatted string. globus_result_t globus_scheduler_event_failed (time_ttimestamp, const char *jobid, intfailure_code) Send a job failed event to the JobSchedulerMonitor implementation. Parameters: timestamp Timestamp to use for the event. If set to 0, the time which this function was called is used. jobid String indicating the scheduler-specific name of the job. failure_code Failure code of the process if known. Return values: GLOBUS_SUCCESS Scheduler message sent or queued. GLOBUS_SEG_ERROR_NULL Null jobid. GLOBUS_SEG_ERROR_INVALID_FORMAT Unable to determine length of formatted string. globus_result_t globus_scheduler_event_done (time_ttimestamp, const char *jobid, intexit_code) Send a job done event to the JobSchedulerMonitor implementation. Parameters: timestamp Timestamp to use for the event. If set to 0, the time which this function was called is used. jobid String indicating the scheduler-specific name of the job. exit_code Exit code of the process if known. Return values: GLOBUS_SUCCESS Scheduler message sent or queued. GLOBUS_SEG_ERROR_NULL Null jobid. GLOBUS_SEG_ERROR_INVALID_FORMAT Unable to determine length of formatted string. globus_result_t globus_scheduler_event_generator_get_timestamp (time_t *timestamp) Get the timestamp for the earliest event an SEG module should send. Parameters: timestamp Pointer to a time_t which will be set to the timestamp passed to the SEG executable. The module should not send any events which occur prior to this timestamp. Return values: GLOBUS_SEG_ERROR_NULL Null timestamp. GLOBUS_SUCCESS Timestamp value updated. If the timestamp was not set on the SEG command-line, then the value pointed to by timestamp will be set to 0. Author Generated automatically by Doxygen for globus scheduler event generator from the source code. Version 4.6 Mon Apr 30 2012 Scheduler Implementation API(3)
All times are GMT -4. The time now is 03:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy