Batch file to extract first line of data

June 7, 2010 at 06:59:13
Specs: Windows XP
Hi all, found this nice resource thanks to google, but having read some of the various batch file requests I couldn't see one that matched my here goes:

I have a directory full of .zrf files (which can be opened in notepad so hopefully all text!) - and I need to create one single file which takes the last four digits of the filename (preceding the file extension) of all the files in the directory, and appends to this the text string from the first line of each file (which always begins.. 'ORIGINAL_IMAGE_NAME l:' if that makes any difference)

does that make sense?

the file naming convention for the zrf files is also always the same : 'P1Ref0000XXXX'

Any help is MUCH appreciated - I've really messed something up at work and this is the only way to solve my problem.


See More: Batch file to extract first line of data

Report •

June 7, 2010 at 09:03:58
@echo off >zrf.txt & setlocal enabledelayedexpansion
for /f %%a in ('dir /b /a-d *.zrf') do (
set nn=%%~na
set nn=!nn:~-4!
set line=
set /p line=<%%a
>> zrf.txt echo !nn!!line!
::------- end
sorry to hear about screwups. I've made a few myself, so i
can sympathize. HtH

Report •

June 7, 2010 at 09:10:27
oh YES.

Worked a treat, you are a real life saver.

I can't thank you enough - without this I'd have had to read each file and cut and paste the data!

Many many thanks... I'll stop gushing now.

Report •
Related Solutions

Ask Question