Windows batch file: extracting lines of text

November 3, 2010 at 10:25:14
Specs: Windows XP
I have only written a few batch files and I have only done very simple things to automate my work. I have a big analysis to do and I really need help automating it or it will be impossible. I have 100 text files that are output from a program. I would like to go through the 100 files and extract a single line of text from each to copy into a new file that would contain all 100 lines in the same file. The line begins with a unique string followed by 16 numbers. There are spaces between the string and the numbers. As an example,
uniquestring 1.0 128 32 32 22 22 27 0 5.5 7.6 10.8 1.0 2.0 1.0 4.0 13.0
I would really appreciate any help.

See More: Windows batch file: extracting lines of text

Report •

November 3, 2010 at 10:44:14
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
findstr /b "uniquestring" %%a >> newfile

Life is too important to be taken seriously.


Report •

November 3, 2010 at 10:47:31
At prompt type mybat Folder_Name where Folder_Name is the folder holding your 100 text files.

:: MYBAT.BAT Usage mybat Folder_Name
@ech off
pushd %*
if exist FileNew.txt del FileNew.txt
for %%j in (*.txt) do type "%%j" | find "uniquestring" >>
ren *.txt
:: End_Of_Batch

Report •

November 4, 2010 at 01:56:40
M2 and Ivo, thank you very much. Both batch files work perfectly and having an example of two ways to solve the problem really helps me to figure out looping. Can either of you recommend any reading material for Windows command? I know unix and linux, but windows command books are really hard to find.

Report •

Related Solutions

November 4, 2010 at 02:15:19

Happy is ONE who says I am an OttoMAN.

Report •

Ask Question