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-08-09 01:24
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please explain this batch file of yours, zw19750516 View 669 Replies 1
Original Poster Posted 2008-06-20 18:10 ·  中国 山东 潍坊 联通
初级用户
★★
Credits 73
Posts 51
Joined 2007-08-31 10:04
18-year member
UID 96241
Gender Male
Status Offline
@echo off
for /f "tokens=3,5,7,8 delims==/> " %%i in ('findstr "FACTORY DUT" 1.txt^|findstr /v "FIXTURE"') do call :lp %%i %%j %%k %%l
pause>nul&goto :eof
:lp
set str=%1
if defined str echo %str:~1,-1%
if defined str shift&goto lp

Thanks, and experts are also welcome to chime in.
Floor 2 Posted 2008-06-20 18:31 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
Sheesh, why does everyone want an explanation.
What comes before :lp is using suitable delimiters and a for+findstr statement to grab the wanted strings from 1.txt, so I won't explain that in detail.
I believe newbies may have a bit of trouble understanding the shift statement after the :lp label. Actually, if you just type shift /? in cmd, you can get a basic idea that what shift does is shift the parameters after call. And here shift is doing the same thing: first, four parameters are passed over from the for statement, namely %%i %%j %%k %%l, that is, %1 %2 %3 %4. Each time lp loops once, shift moves the parameters one place back. The first time, the parameter is %1=%%i, but the second time %1 moves to the second position, so now %1=%%j, and this continues until %1 has been shifted to the position of the last parameter.

[ Last edited by zw19750516 on 2008-6-20 at 06:34 PM ]
批处理之家新域名:www.bathome.net
Forum Jump: