2

I have a log file where the first line is very long and full of strange (ASCII?) characters. There is a timestamp in there that I need to extract so I can rename the file. That line looks like this:

MDF             CANwin I    ,                                  HD¤ ¶ (¶      21:12:202214:14:44                                                                                                                                  Q    p       e™    Ñ     48-375Šš    Q    `       øš    Ñ    -001   œ    Q    @    yœ    Ñ    Cpz  «    𨱌   ÿÿÿÿÿÿ¸ž    ðóÿ”  ÿÿÿÿÿÿÿTóž    àôÿˆ  ...

I need to extract the timestamp 21:12:202214:14:44.

This will only return line1 as "MDF":

@echo off
setlocal enabledelayedexpansion enableextensions
set name=%~n1
set /p line1=< %name%.log
echo %line1%

I realize there are limits to /p but this is the only way I've gotten any output.

Edit: These files are coming from a memorator on a vehicle in Vector Log (.log) format. They are "readable" in Notepad.

workman7
  • 21
  • 2
  • With the `MDF` magic number, it's more likely that instead of being a regular log file, this is actually a SQL Server database. You may want to read https://stackoverflow.com/questions/1175882/what-is-an-mdf-file or https://serverfault.com/questions/31105/opening-mdf-files about accessing them more effectively. – SomethingDark Mar 24 '23 at 23:01

1 Answers1

0
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET /p "line="<q75837443.txt
FOR %%e IN (%line%) DO (
 SET "datestring=%%e"
 IF "!datestring:~2,1!!datestring:~5,1!!datestring:~12,1!!datestring:~15,1!"=="::::" GOTO found
 SET "datestring="
)
:found
SET datestring
GOTO :EOF

Where q75837443.txt is your log file.

Read the line, then simply assign each space-separated element to %%e and datestring in turn. If the 2nd,5th,12th,15th character in datestring (counting from the start=0th character) are all colons, go to found with the string.

Magoo
  • 77,302
  • 8
  • 62
  • 84