|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『楼 主』:
怎样复制指定内容到指定文件里去
使用 LLM 解释/回答一下
WinXP下,想复制1.txt第三行之后的所有文本内容到一个指定的文本文件中去,请问如何实现?
Under Windows XP, if you want to copy all the text content after the third line of 1.txt to a specified text file, how can you achieve it?
|
|
2006-3-31 21:55 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /f "skip=3 tokens=*" %i in (1.txt) do @echo %i >>指定文件.txt
如果在批处理中使用将%i更改为%%i
```
for /f "skip=3 tokens=*" %%i in (1.txt) do @echo %%i >>指定文件.txt
```
|
|
2006-4-1 07:50 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
那如果只要其中的几行呢?比如一个文本文件有100行,现在只需要其中的20~25行和30行之后的内容,该如何编写呢?
另外,如果想让提取后的文件内容格式与原文件格式保持一致,比如在35行到40行之间有空行,并且有文字的行行首都有空格,该如何实现?
Last edited by namejm on 2006-4-1 at 13:14 ]
Then how to get only a few lines? For example, if a text file has 100 lines, and now we only need lines 20 - 25 and the content after line 30, how to write it?
In addition, if you want the format of the extracted file content to be consistent with the original file format, for example, there are blank lines between lines 35 to 40, and the first line of lines with text all have spaces, how to achieve it?
Last edited by namejm on 2006-4-1 at 13:14 ]
|
|
2006-4-1 12:59 |
|
|
chenhui530
高级用户
   
积分 772
发帖 273
注册 2004-10-23
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
用批处理实现起来应该很复杂用VBS来就简单很多
It should be quite complicated to implement with batch processing, while it's much simpler with VBS.
|

http://www.msfans.net/bbs/ |
|
2006-4-1 16:50 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
试试Horst的Lmod程序。
Try Horst's Lmod program.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2006-4-1 19:07 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
你可以尝试用 sed 解决一下
sed -n "3,$p" 1.txt >temp.txt
sed 下载地址:
http://www.student.northpark.edu/pemente/sed/gsed407x.zip
You can try to solve it with sed
sed -n "3,$p" 1.txt >temp.txt
Sed download address:
http://www.student.northpark.edu/pemente/sed/gsed407x.zip
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-4-2 00:55 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
想不借助第三方软件,仅通过DOS批处理来实现,会很复杂么?
Is it very complicated to achieve only through DOS batch processing without relying on third-party software?
|
|
2006-4-2 12:44 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
同意4楼。
with CreateObject("SAFRCFileDlg.Fileopen")
.openfileopendlg
if not len(trim(.filename)) = 0 then
oldfilename = .filename
else
msgbox "没有选择文件!"
wscript.quit
end if
end with
newfilename = left(oldfilename,len(oldfilename) - 4) & "cxs" & right(oldfilename,4)
number1 = inputbox("输入起始行号:")
number2 = inputbox("输入行数:")
with createobject("scripting.filesystemobject")
set rfile = .opentextfile(oldfilename,1,true)
set wfile = .opentextfile(newfilename,2,true)
for i = 1 to number1
rfile.skipline
next
for j = 1 to number2
str = rfile.readline
wfile.writeline str
next
end with
保存为 文件处理.vbs 然后双击运行,大致可以满足你的要求。当然,你也可以在批处理里面把代码写到一个vbs文件达到批处理的效果,如果那样的话可以把前面的对话框部分去掉,再加上参数。唉,应该用adodb的,可惜忘记了.
Agree with the 4th floor.
with CreateObject("SAFRCFileDlg.Fileopen")
.openfileopendlg
if not len(trim(.filename)) = 0 then
oldfilename = .filename
else
msgbox "No file selected!"
wscript.quit
end if
end with
newfilename = left(oldfilename,len(oldfilename) - 4) & "cxs" & right(oldfilename,4)
number1 = inputbox("Enter the starting line number:")
number2 = inputbox("Enter the number of lines:")
with createobject("scripting.filesystemobject")
set rfile = .opentextfile(oldfilename,1,true)
set wfile = .opentextfile(newfilename,2,true)
for i = 1 to number1
rfile.skipline
next
for j = 1 to number2
str = rfile.readline
wfile.writeline str
next
end with
Save it as "File Processing.vbs" and then double-click to run, which can roughly meet your requirements. Of course, you can also write the code into a vbs file in the batch processing to achieve the effect of batch processing. In that case, you can remove the previous dialog box part and add parameters. Oh, I should have used adodb, but I forgot.
|
|
2006-4-2 12:45 |
|