Leonidas Georgiou Leonidas Georgiou - 2 months ago 15
Bash Question

Keno number parser

Trying to make a script that will process Keno numbers in order to perform various pattern finding operations.

Each line of data looks like this:


576186 15/9/2016 21:50 8 9 12 15 22 26 32 37 39 46 49 54 57 58 59 61 67 68 70 71


This is my code blatantly taken from another post on stackoverflow but modified slightly.

for /f "tokens=1 delims=" %%f in (Keno.txt) do (
set line=%%f
call :processToken
)
goto :eof

:processToken
for /f "tokens=1* delims= " %%a in ("%line%") do (
echo Got one token: %%a
set line=%%b
pause
)
if not "%line%" == "" (
goto :processToken
)
goto :eof


I'm trying to truncate the first 3 delimiters of each line before I begin processing the raw Keno numbers but I am unable to truncate using the:
~-4%
function on
%%f
or
%%a
to do this properly. I've tried various obvious methods to achieve this by doing
set string=%%f
and then
set string=%string:~-4
for example, but this doesn't work even with
!!
or
%%
characters.

Anyone who knows how to do this?

I need this:


576186 15/9/2016 21:50 8 9 12 15 22 26 32 37 39 46 49 54 57 58 59 61 67 68 70 71


To look like this:


8 9 12 15 22 26 32 37 39 46 49 54 57 58 59 61 67 68 70 71

Answer

try this:

@echo off
for /f "usebackq tokens=1* delims=:" %%a in ("keno.txt") do (
    rem echo %%b
     set "flag="
     for %%# in (%%b) do (
         if defined flag (
             echo|set/p"=%%# "
         ) else (
            set "flag=1"
         )
     )
)
Comments