Solved how to write Batch file for extract data between same words?

February 7, 2017 at 04:41:18
Specs: Windows 7
Hi..I want to extract data from starting with a ERROR letter and till another ERROR Word occurs ex:
ERROR 2017-02-01 05:43:26,065 [Thread-34853] iks
ERROR 2017-02-01 05:43:26,172 [Thread-34853] iks_ve
ERROR 2017-02-01 05:43:26,174 [Thread-34853] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR -
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
java.net.SocketInputStream.read(SocketInputStream.java:170)
java.net.SocketInputStream.read(SocketInputStream.java:141)
java.net.SocketInputStream.read(SocketInputStream.java:127)
java.lang.Thread.run(Thread.java:745)
ERROR 2017-02-01 05:43:35,027 [Thread-34854] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR - IMEI:356449062777353VEHICLE DOESNT EXISTS!!!..PLS ADD ENTRY
ERROR 2017-02-01 05:43:35,030 [Thread-34854] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR - java.net.SocketException: Socket closed
ERROR 2017-02-01 05:43:35,030 [Thread-34854] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR -
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
java.net.SocketInputStream.read(SocketInputStream.java:170)
java.net

I want that Form ERROR Word it reads till Start of another ERROR Word.. and stores in another text file
please help me..Thank you

message edited by chandrukase


See More: how to write Batch file for extract data between same words?

Report •

#1
February 8, 2017 at 07:42:56
So you want (in this example) 6 .txt files containing a diffrent ERROR(+MESSAGE)
Example output should look like this right?:

err1.txt:
ERROR 2017-02-01 05:43:26,065 [Thread-34853] iks

err2.txt:
ERROR 2017-02-01 05:43:26,172 [Thread-34853] iks_ve

err3.txt:
ERROR 2017-02-01 05:43:26,174 [Thread-34853] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR -
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
java.net.SocketInputStream.read(SocketInputStream.java:170)
java.net.SocketInputStream.read(SocketInputStream.java:141)
java.net.SocketInputStream.read(SocketInputStream.java:127)
java.lang.Thread.run(Thread.java:745)

err4.txt:
ERROR 2017-02-01 05:43:35,027 [Thread-34854] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR - IMEI:356449062777353VEHICLE DOESNT EXISTS!!!..PLS ADD ENTRY

err5.txt
ERROR 2017-02-01 05:43:35,030 [Thread-34854] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR - java.net.SocketException: Socket closed

err6.txt
ERROR 2017-02-01 05:43:35,030 [Thread-34854] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR -
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
java.net.SocketInputStream.read(SocketInputStream.java:170)
java.net

-----------------------

working on it:

::start of test.bat
@echo off&setlocal EnableDelayedExpansion
for /f "tokens=1-8 delims=:., " %%a in ('type FULLERROR.txt ^| findstr "ERROR 20"') do (
echo "%%a %%b %%c-%%d-%%e-%%f %%g %%h.txt"
)
::end of test.bat

preview output:

test
"ERROR 2017-02-01 05-43-26-065 [Thread-34853] iks.txt"
"ERROR 2017-02-01 05-43-26-172 [Thread-34853] iks_ve.txt"
"ERROR 2017-02-01 05-43-26-174 [Thread-34853] iks_vehicle_data_collector.txt"
"ERROR 2017-02-01 05-43-35-027 [Thread-34854] iks_vehicle_data_collector.txt"
"ERROR 2017-02-01 05-43-35-030 [Thread-34854] iks_vehicle_data_collector.txt"
"ERROR 2017-02-01 05-43-35-030 [Thread-34854] iks_vehicle_data_collector.txt"

Simple solutions are often the best

message edited by hidde663


Report •

#2
February 9, 2017 at 07:06:16
✔ Best Answer
Got it working with just 3 lines of code :D

All you need to change is "FULLERROR.txt" to whatever your textfile is called

save as test.bat and run from the folder where the big error log is saved

::start of test.bat

@echo off&setlocal EnableDelayedExpansion&set skip=0
set file=FULLERROR.txt
if '!skip!'=='0' for /f "tokens=1-31 delims=:., " %%a in ('type %file%') do if '%%a'=='ERROR' (set "newerror=%%a %%b %%c-%%d-%%e-%%f %%g %%h %%i %%j %%k %%l %%m %%n"&echo %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z>>!newerror!.txt) else (echo %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z>>!newerror!.txt)

::end of test.bat

could you let me know if it works?

Simple solutions are often the best

message edited by hidde663


Report •
Related Solutions


Ask Question