Solved How to extract a section of text from text file in DOS?

January 10, 2013 at 13:02:22
Specs: Windows Vista
I need to extract a string based on criteria (not a line) from text (log) file.
e.g.
MAXL> import database "'MTHR1_A'"."'MOTHER'" data
2> from local data_file "'D:/ARCHIVE/2012_11_Working_Version_November.txt'"
3> using server rules_file "'lVrsCpy'" to load_buffer with buffer_id 1
4> on error write to "'/Hyperion/products/Essbase/EssbaseClient/client/MTHR1/MOTHER/Build_Load_ASO.x.lVrsCpy.err'";

OK/INFO - 1019061 - Reading Rule SQL Information For Database [MOTHER].
OK/INFO - 1019025 - Reading Rules From Rule Object For Database [MOTHER].
OK/INFO - 1003040 - Parallel dataload enabled: [1] block prepare threads, [1] block write threads..
WARNING - 1003055 - Aggregate storage applications ignore update to derived cells. [18604] cells skipped.
WARNING - 1003065 - Data load stream contains [1.54183e+007] zero and [0] #MISSING cells.
OK/INFO - 1003053 - Data Load Elapsed Time with [lVrsCpy.rul] : [95.797] seconds.
WARNING - 1241114 - There were errors, look in /Hyperion/products/Essbase/EssbaseClient/client/MTHR1/MOTHER/Build_Load_ASO.x.lVrsCpy.err.
OK/INFO - 1241113 - Database import completed ['MTHR1_A'.'MOTHER'].

essmsh timestamp: Fri Dec 14 09:30:09 2012


essmsh timestamp: Fri Dec 14 09:30:09 2012


essmsh timestamp: Fri Dec 14 09:30:09 2012

MAXL> import database "'MTHR1_A'"."'MOTHER'" data
2> from local data_file "'D:/ARCHIVE/2012_10_Working_Version_October.txt'"
3> using server rules_file "'lVrsCpy'" to load_buffer with buffer_id 1
4> on error write to "'/Hyperion/products/Essbase/EssbaseClient/client/MTHR1/MOTHER/Build_Load_ASO.x.lVrsCpy.err'";

OK/INFO - 1019061 - Reading Rule SQL Information For Database [MOTHER].
OK/INFO - 1019025 - Reading Rules From Rule Object For Database [MOTHER].
OK/INFO - 1003040 - Parallel dataload enabled: [1] block prepare threads, [1] block write threads..
WARNING - 1003055 - Aggregate storage applications ignore update to derived cells. [27412] cells skipped.
WARNING - 1003065 - Data load stream contains [1.62265e+007] zero and [0] #MISSING cells.
OK/INFO - 1003053 - Data Load Elapsed Time with [lVrsCpy.rul] : [90.985] seconds.
WARNING - 1241114 - There were errors, look in /Hyperion/products/Essbase/EssbaseClient/client/MTHR1/MOTHER/Build_Load_ASO.x.lVrsCpy.err.
OK/INFO - 1241113 - Database import completed ['MTHR1_A'.'MOTHER'].


There is more text before and after this sample.

I need to extract - D:/ARCHIVE/2012_11_Working_Version_November.txt and D:/ARCHIVE/2012_10_Working_Version_October.txt from following:
2> from local data_file "'D:/ARCHIVE/2012_11_Working_Version_November.txt'"
2> from local data_file "'D:/ARCHIVE/2012_10_Working_Version_October.txt'"
based on criteria - Build_Load_ASO.0.lVrsCpy.err

criteria in the text is Build_Load_ASO.x.lVrsCpy.err

How can I do this using DOS commands?

The result should be -
D:/ARCHIVE/2012_11_Working_Version_November.txt
D:/ARCHIVE/2012_10_Working_Version_October.txt

Thank you
Dave


See More: How to extract a section of text from text file in DOS?

Report •


✔ Best Answer
January 24, 2013 at 19:39:48
Did not work.
But when I replaced *for /f "tokens=7,9,10 delims=," %%a in (testfile) do ( *
with *for /f %%i in (%SourceDir%\%DestFile3%) do (for /f "tokens=7,9,10 delims=," %%a in (%%i) do ( *
then it worked.
Once again thank you very very much.


#1
January 10, 2013 at 18:23:18
This may or may not work (I took liberties with the qualifying string you provided):
:: begin batchscript
@echo off>errlog & setlocal
for /f "tokens=1-3 delims=>-'" %%a in (log) do (
if "%%a" equ "2" set x=%%c
if "%%a" equ "4" set err=%%~nxc
if "%%b" equ " 1241114 " call :report
)
goto :eof
:report
>> errlog echo %x% %err%

Report •

#2
January 11, 2013 at 23:16:12
Thanks for the reply <nbrane>. . There is error file with list of file names. e.g.
Build_Load_ASO.x.lVrsCpy.err
Build_Load_ASO.x.CF.err
Build_Load_ASO.x.HD.err
etc...

Can you fix the above code so the output (>> errlog echo %x%) matches the list in err file. Your code extracts all the "2" and "1241114".

For "Build_Load_ASO.x.CF.err" match in (log) and print "D:/ARCHIVE/2012_11_Working_Version_November.txt"

For "Build_Load_ASO.x.HD.err" match in (log) and print "D:/ARCHIVE/2012_11_Working_Version_October.txt"


Report •

#3
January 12, 2013 at 12:53:02
I sort of think I understand what you want, but not real sure. Try the revised code in response #1 and let me know.

Report •

Related Solutions

#4
January 23, 2013 at 16:05:35
I need to get one record from 2 records from this example:
"2012","1324","4345","SC132","TER",A213","32B","CET","BottlesConv",0,133
"2012","1324","4345","SC132","TER",A213","32B","CET","Litreconv",0,133

"US","2012","2134","3345","SC132","TER","32B",A213","CET","BottlesConv",0,123
"US","2012","2134","3345","SC132","TER","32B",A213","CET","Litreconv",0,123

Result:32B BottlesConv/Litreconv
*************************************************************************

for /f %%i in (%SourceDir%\%DestFile3%) do (for /f "tokens=7,9,10 delims=," %%a in (%%i) do (
set st=%%a
set sb=%%b
set sc=%%c
if /i not !sb!=="BottlesConv" if /i not !sb!=="Litreconv" set sb="Error"
if /i not !sc!=="BottlesConv" if /i not !sc!=="Litreconv" set sb="Error"
if /i !sb!==!sc! set tr="BottlesConv/Litreconv"
set rst=!st:"=!
set rsb=!sb:"=!
set rtr=!tr:"=!
echo !rst! !rtr! >> %SourceDir%\%DestFile%
))

******************************************************************************

What does this mean:
(if /i a=A1 if /i b=A2 if /i c=B1 if /i d=A2) set x=something

Can we use AND...OR
(IF x=x AND IF y=y) OR (IF a=a OR IF b=b)

Thank You,
Dave


Report •

#5
January 23, 2013 at 19:53:19
might work, not sure:
@echo off & setlocal enabledelayedexpansion
set out=

for /f "tokens=7,9,10 delims=," %%a in (testfile) do (
set sa=%%~a
call :%%~b %%~b 2>nul >> xxx
call :%%~c %%~c 2>nul >> xxx
)
goto :eof

:bottlesconv
:litreconv
if defined out (
echo !sa! !out!/%~1
set out=
) else (
set out=%~1
)
::===== end


Report •

#6
January 24, 2013 at 19:39:48
✔ Best Answer
Did not work.
But when I replaced *for /f "tokens=7,9,10 delims=," %%a in (testfile) do ( *
with *for /f %%i in (%SourceDir%\%DestFile3%) do (for /f "tokens=7,9,10 delims=," %%a in (%%i) do ( *
then it worked.
Once again thank you very very much.

Report •

#7
January 24, 2013 at 19:56:54
AAAH! DUH ME! sorry, not sure how that happened. Too many budweisers i guess.
Guilty as charged for P.U.I
(Programming Under the Influence) :-(

Report •


Ask Question