Extracting a string of text from a txt file

March 31, 2011 at 07:48:00
Specs: Windows 7
What I am trying to accomplish is to extract the second line of text from multiple files and create a listing of that data into one file. I am trying to modify a batch file that was used by Mechanix2go on a similar solution. I have that program listed here. The text files are actually .DAT files and I want to exstrapulate the second string to use in a listing format into a .txt file. Each directory contains anywhere from 10 to 200 dat files, I have 130 directories.

::== firstLIN.bat
@echo off
if %1'==' echo which file? && goto :eof

set DONE==N
for /f "tokens=*" %%L in (%1) do call :1 %%L
goto :eof

:1
if %DONE%==Y goto :eof
echo %*>outFILE
set DONE=Y
goto :eof

:eof
:: DONE


See More: Extracting a string of text from a txt file

Report •


#1
March 31, 2011 at 09:03:06
I have been looking to modify something that is exsisting for a batch file to extract line 2 of a dat file. Here is another source program that I have found. Need some guidance to modify parameters to accept wildcards and it seems thats not understood.

set /a N=0
set offsetup=0
set offsetdown=0

for /f "tokens=* delims=" %%a in (p*.dat) do (
set /a N+=1
set curr=%%a
if "!curr!" equ "START_PATTERN" (secondline
set /a pre=!N!-1+!offsetup!
)
set prev=!curr!
)

set /a N=0

for /f "tokens=* delims=" %%a in (part002.dat) do (
set /a N+=1
set curr=%%a
if "!curr!" equ "END_PATTERN" (thirdline
set /a post=!N!+1+!offsetdown!
)
set prev=!curr!
)

set /a N=0

for /f "tokens=* delims=" %%a in (part002.dat) do (
set /a N+=1
set str=%%a
if !N! gtr !pre! if !N! lss !post! (echo !str! >> listing.txt)


Report •

#2
April 1, 2011 at 08:07:00
O.K. After digging out my Old Dos book I realized that Windows 7 still has the commands available to Findstr and Sort.

I was able to write a batchfile with one string for me to perform my feat.

Thanks anyways for no-one replying... but myself.

findstr "PN" P*.dat | sort/+16 >2-smallparts.txt


Report •

Related Solutions


Ask Question