在NT CMD下,要提取一TXT文件中第N行(如第5行)中的从40列开始的6个字符并使之成为一变量。要求不要用第三方软件,请达者告知。
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
从40列开始
more +40 C:\somefile.txt
Originally posted by electronixtar at 2006-8-27 16:06:
As far as I know, try this command:
more +40 C:\somefile.txt
This can print the 40th line to screen, and use Cmd variables to cut string from the the 6th, use 'for' to se ...
:dosomething
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=: tokens=1,2" %%i in ('findstr /n . %1 ^| findstr "^%2" ') do set "str=%%j"
if "!str:~%3,1!" == "" (echo 该行没有第%3个字符... && goto :eof)
echo !str:~%3,1!
endlocal
goto :eof
:dosomething
set/a X=%3-1
set N=0
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in (%1) do (set/a N=!N!+1
if "!N!"=="%2" set "str=%%i"&goto str)
:str
if "!str:~%X%,1!"=="" echo 该行没有第%3个字符&goto :eof
if "!str:~%X%,1!"==" " echo 该行第%3个字符是空格&goto :eof
echo !str:~%X%,1!
endlocal
goto :eof
Originally posted by NaturalJ0 at 2006-8-28 09:44:
for /f "skip=4 tokens=*" %%i in (file.txt) do (
set str=%%i
goto OUTFOR)
:OUTFOR
set str=%str
强!测试通过!太感谢了!再请问一下高手:如果要查找该文本文件中所有行的第40列开始的6个字符,有没有简化的方法?
Originally posted by NaturalJ0 at 2006-8-28 17:32:
我试有内容啊