0

Windows batch command(s) to read first line from text file

As discussed in the above article, one can use the below code to get the first line. The limitation is however that only the first 1026 bytes are copied. My headers are longer. How can I avoid this limitation?

set /p texte=< "C:\Users\swuyts\Desktop\PMO
Dashboard\Sourcefiles\Pentana\Landingsarea\PlannedHours_Pentana.txt"
echo %texte% > "C:\Users\swuyts\Desktop\PMO
Dashboard\Sourcefiles\Pentana\Landingsarea\PlannedHours_Pentana_headers.txt"
Community
  • 1
  • 1
user1186098
  • 43
  • 1
  • 1
  • 8

1 Answers1

0

To be used from command line

for /f "tokens=1,* delims=:" %a in ('findstr /n "^" "%inputFile%" ^| findstr /b /c:"1:"') do ( >"%outputFile%" echo %%b)

Before executing, assign variables or replace them in the command with full file references.

BUT you are still limited, in this case to 8191 characters.

MC ND
  • 69,615
  • 8
  • 84
  • 126