0

Well I have that code:

@echo off
FOR /F "tokens=* skip=3" %%A IN (abc.txt) DO (echo.%%A)
pause

In abc.txt:

a
b
c
d
e
f
g
h
i
j
k
l
m
n
ñ
o
p
q
r
s
t
u
v
w
x
y
z

I want to read only the third line and no more...

How can I do that? :/

Seazoux
  • 621
  • 1
  • 5
  • 28
  • check this tool that I've written:->http://ss64.org/viewtopic.php?id=1707 .The `FOR` version on my last but one post is preferable.There's a help too.It's pretty robust and will read even special symbols like !&%.. – npocmaka Sep 07 '13 at 11:55

3 Answers3

1
@echo off
set /a "skip=%~1" || exit /b

if %skip% gtr 0 (set skip=skip=%skip%) else (set skip=)
set "value="
for /f "usebackq %skip% delims=" %%A in ("abc.txt") do (
  set "value=%%A"
  goto :done
)
:done
echo value=%value%

FOR /F does not support "skip=0", hence the if statement before the loop.

dbenham
  • 127,446
  • 28
  • 251
  • 390
0

Wow! I have solved it:

@echo off
set /a count=6
if defined count for /f "skip=%count%tokens=1*delims=:" %%i in ('findstr /N "^" "abc.txt"') do if not defined value set "value=%%j"
echo %value%

Output: g

:D

Seazoux
  • 621
  • 1
  • 5
  • 28
  • That is a convoluted way to almost get a working solution :) It does not work with a skip (count) of 0. – dbenham Sep 07 '13 at 13:45
  • It will also be very slow with very large files because the entire output of the FINDSTR command must be buffered before any data is read. It could be sped up by piping to a second FINDSTR to look for the desired line, but that solution is more complicated than is needed. – dbenham Sep 07 '13 at 13:56
0

This uses a helper batch file called findrepl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=4697

type abc.txt |findrepl /o:3:3

findrepl.bat is a handy addition to your tools.
In this usage it sets the start line and end line to the same number /o:S:E

foxidrive
  • 40,353
  • 10
  • 53
  • 68