China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-02 16:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to skip the first two lines, the last two lines, and blank lines, and read the first column of a file? View 745 Replies 4
Original Poster Posted 2007-04-27 22:32 ·  中国 广东 深圳 南山区 电信
初级用户
Credits 28
Posts 10
Joined 2007-02-19 09:47
19-year member
UID 79788
Gender Male
Status Offline
for /f "skip=2 tokens=1" %%1 in (result.txt) do echo %%1>>new.txt
SET A=1
FOR /F "TOKENS=1* DELIMS=:" %%A IN ('FINDSTR /N .* new.txt') DO (
echo %%B
SET/A B=!A!%%100
IF !B! EQU 0 (ping -n 15 127.1>NUL)
SET/A A+=1
)

This won't skip the last two lines or blank lines.

Is there any way to do it?

Can the file be read only once?
Floor 2 Posted 2007-04-27 23:43 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
There is a difference between first skipping the first two lines and then skipping blank lines, and first skipping blank lines and then skipping the first two lines. OP, please describe the problem clearly.
Floor 3 Posted 2007-04-28 12:04 ·  中国 广东 深圳 南山区 电信
初级用户
Credits 28
Posts 10
Joined 2007-02-19 09:47
19-year member
UID 79788
Gender Male
Status Offline
First skip the first two lines, then skip the last two lines and blank lines.

The blank lines are at the very end of the file. There are two lines.
Floor 4 Posted 2007-04-29 00:27 ·  中国 广东 深圳 南山区 电信
初级用户
Credits 28
Posts 10
Joined 2007-02-19 09:47
19-year member
UID 79788
Gender Male
Status Offline
The purpose is to read the first column between the first two lines and the last two lines. The blank lines are after the last two lines.
Floor 5 Posted 2007-04-29 04:51 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Since the last two lines of the file are blank lines, the for command can ignore them automatically.
@echo off
for /f "skip=2" %%a in (1.txt) do echo\%%a
Forum Jump: