1

I need the batch code to copy the FIRST line of multiple text files into a new text file and append original filenames to each line, and if possible a way of editing the batch code to any LINE number one wants.

Thanks

Mark
  • 3,609
  • 1
  • 22
  • 33
  • Possible duplicate of [Use batch file to copy first 6 lines to a new txt file](http://stackoverflow.com/questions/11044146/use-batch-file-to-copy-first-6-lines-to-a-new-txt-file) –  Mar 17 '16 at 15:19

2 Answers2

1

This uses a helper batch file called findrepl.bat from - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat

Place findrepl.bat in the same folder as the batch file or on the path.

@echo off
set linenum=1
for %%a in (*.txt) do (
   type "%%a"|findrepl /o:%linenum%:%linenum% >>tmp.tmp
)
move /y tmp.tmp "Result.txt"
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0
@ECHO OFF &SETLOCAL
for %%a in (*.txt) do (
    set "line="
    set /p "line="<"%%~a"
    SETLOCAL ENABLEDELAYEDEXPANSION
    echo(!line!
    endlocal
)
Endoro
  • 37,015
  • 8
  • 50
  • 63