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-01 05:37
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to copy specified content into a specified file View 3,840 Replies 7
Original Poster Posted 2006-03-31 21:55 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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?
Floor 2 Posted 2006-04-01 07:50 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
for /f "skip=3 tokens=*" %%i in (1.txt) do @echo %%i >>指定文件.txt
```
Floor 3 Posted 2006-04-01 12:59 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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 ]
Floor 4 Posted 2006-04-01 16:50 ·  中国 重庆 巴南区 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
It should be quite complicated to implement with batch processing, while it's much simpler with VBS.
http://www.msfans.net/bbs/
Floor 5 Posted 2006-04-01 19:07 ·  中国 河北 保定 移动
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Try Horst's Lmod program.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 6 Posted 2006-04-02 00:55 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
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

Floor 7 Posted 2006-04-02 12:44 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Is it very complicated to achieve only through DOS batch processing without relying on third-party software?
Floor 8 Posted 2006-04-02 12:45 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
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.
Forum Jump: