Reading Line of file, and formatting it

I know you all can help but I always try and figure it out on my own.

I have a line in a file that starts with the Day of the week (3 characters), The date, in this format MM/DD/YYYY and then the time of day. Just FYI, its a log file and the rest of the line returns a comma, the computer name, another comma and then the log entries. The very first line returns the script name that created the log and the version. Like this…

Tue 09/03/2024 8:43:21.88, My Little Script, Script Rev. 3

I am trying to get the date, using relevance, to format in this way…

YYYYMMDD

Getting the time would be helpful too, in this format…

HHMM (no need for seconds)

To end up with something like this.

YYYYMMDDHHMM

I can get the line, and get the year and everything after it, but not sure how to get the rest of what I need.

q: line 1 of it of file "C:\scripts\MyLittleScriptLog.log"
A: Tue 09/03/2024 8:43:21.88, Computer-SF, My Little Script Rev. 3
T: 2.464 ms

q: following texts of last "/" of (line 1 of it of file "C:\scripts\MyLittleScriptLog.log")
A: 2024 8:43:21.88, Computer-SF, My Little Script Rev. 3
T: 1.760 ms

The first thing I do not like about this is it assumes that the “/” is the last one in the line. In this log, and other logs I will use it on, it will always be the last “/” but I don’t want to assume.

I don’t know how to get X num of charters after a string I find.

I always welcome your suggestions.

It may take some time before I can dig into this, but you’ve get the main clue in your post already. You said

So, you already know that the date/timestamp is everything before the first comma, or preceding text of first "," of ...

so that should get you the date & timestamp by itself - and then you’ll have a predictable pattern within the date/time.

Starting from Jason’s observation:

Q: following texts of firsts " " of preceding texts of firsts "," of lines of file "C:\scripts\MyLittleScriptLog.log"
A: 09/03/2024 8:43:21.88
A: 09/04/2024 13:21:50.33
T: 1.101 ms
 I: plural substring

The following creates a tuple with all the required elements in their proper order:

Q: (preceding texts of lasts " " of following texts of last "/" of it, preceding texts of first "/" of it, following texts of first "/" of preceding texts of last "/" of it, following texts of firsts " " of preceding texts of first ":" of it, preceding texts of first ":" of following texts of first ":" of it) of (following texts of firsts " " of preceding texts of firsts ", " of lines of file "C:\scripts\MyLittleScriptLog.log")
A: 2024, 09, 03, 8, 43
A: 2024, 09, 04, 13, 21
T: 0.420 ms
I: plural ( substring, substring, substring, substring, substring )

Then finally, concatenate everything, and zero pad the hour and minute:

Q: (item 0 of it & item 1 of it & item 2 of it & last 2 of ("0" & item 3 of it) & last 2 of ("0" & item 4 of it)) of (preceding texts of lasts " " of following texts of last "/" of it, preceding texts of first "/" of it, following texts of first "/" of preceding texts of last "/" of it, following texts of firsts " " of preceding texts of first ":" of it, preceding texts of first ":" of following texts of first ":" of it) of (following texts of firsts " " of preceding texts of firsts ", " of lines of file "C:\scripts\MyLittleScriptLog.log") 

A: 202409030843
A: 202409041321
T: 0.882 ms
I: plural string

Edit: I see now that you only need line 1, so change lines to line 1:

Q: (item 0 of it & item 1 of it & item 2 of it & last 2 of ("0" & item 3 of it) & last 2 of ("0" & item 4 of it)) of (preceding texts of lasts " " of following texts of last "/" of it, preceding texts of first "/" of it, following texts of first "/" of preceding texts of last "/" of it, following texts of firsts " " of preceding texts of first ":" of it, preceding texts of first ":" of following texts of first ":" of it) of (following texts of firsts " " of preceding texts of firsts ", " of line 1 of file "C:\scripts\MyLittleScriptLog.log") 

A: 202409030843
T: 0.852 ms
I: plural string
3 Likes

That’s perfect.

Thanks guys, I really appreciate it.

And for this specific scenario, you can do something like (this covers X characters both before and after a string):

Q: first 4 of following text of first "c" of "abcdefghijklmnopqrstuvwxyz"
A: defg
I: singular substring

Q: first 2 of preceding text of first "c" of "abcdefghijklmnopqrstuvwxyz"
A: ab
I: singular substring
1 Like

Thanks

That is helpful with other things I am working on too.

1 Like