Read TXT file with batch script

MathiAs2Pique_ Posted messages 6 Status Member -  
MathiAs2Pique_ Posted messages 6 Status Member -
Hey.

I need a command that allows me to read line number 2 of a .txt file, but I don't know it.
There's
TYPE lang.txt
but that command writes the entire text document.

2 answers

  1. little boy62 Posted messages 4393 Registration date   Status Member Last intervention   1 790
     
    Hello.

    Try this:
    @echo off set nb=2 set /a N=%nb%-1 set file="c:\users\thomas\desktop\test.txt" for /F "skip=%N% delims=" %%i in ('Type "%file%"') do set "var=%%i" & goto suivant :suivant echo %var% pause

    By putting your own path for the file

    In summary:
    - you skip the previous lines with skip (here line n°1)
    - you retrieve the next line (line n°2)
    - then you exit the for loop (with the goto) to display the content of the line, declared previously.

    ++

    As a wise man once told me: "in France, we have the right to do anything....
    You just have to not get caught."
    2
  2. MathiAs2Pique_ Posted messages 6 Status Member
     
    Ok, I will test.
    0