Solved how to read a file line by line from text file ?

February 8, 2017 at 20:38:08
Specs: Windows 7
I am trying to make a batch file to execute a few things for me.
Now I do understand a few programming languages, but I haven't done much in batch file programming yet.
How to read a file line by line from a particular word till the same word occurs, Because i am also trying read all the line From ERROR word till the ERROR comes back. as given below.how can i do that? Lines are vary every time Between ERROR to ERROR WORD
The code is--------

ERROR 2017-02-01 05:43:26,065 [Thread-34853] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR - IMEI:356449062777353VEHICLE DOESNT EXISTS!!!..PLS ADD ENTRY
ERROR 2017-02-01 05:43:26,172 [Thread-34853] iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR - java.net.SocketException: Socket closed
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)
iks_vehicle_data_collector.IKS_VEHICLE_DATA_COLLECTOR$GoDeviceX.run(IKS_VEHICLE_DATA_COLLECTOR.java:229)
java.lang.Thread.run(Thread.java:745)
ERROR 2017-02-01 05:43:35,027 [Thread-34854]
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)

i nead the out like with ERROR line a sub lines till Which not begin with ERROR word

Any help is greatly appreciated. Thank you


See More: how to read a file line by line from text file ?

Report •

#1
February 9, 2017 at 06:52:39
Code: Reading a Text File One Line at a Time (Visual C#) - https://msdn.microsoft.com/en-us/li...

this may help you
happy to help
lakshan costa


Report •

#2
February 9, 2017 at 07:12:54
✔ Best Answer
have you checked my answer in your previous question from 2 days ago?

link:

https://www.computing.net/answers/w...

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


Report •
Related Solutions


Ask Question