中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-25 23:09
47,812 topics / 349,910 posts / today 0 new / 48,264 members
DOS批处理 & 脚本技术(批处理室) » [Help] Extract the content of a specified line and ignore everything else
Printable Version  2,614 / 10
Floor1 kcdsw Posted 2006-04-25 19:37
中级用户 Posts 179 Credits 404
Hehe, I searched hard all afternoon and still couldn't find a suitable one, so I hope everyone can help me.
Floor2 zhangxue Posted 2006-04-25 19:53
初级用户 Posts 82 Credits 183
lmod seems like it can.
Floor3 kcdsw Posted 2006-04-25 20:51
中级用户 Posts 179 Credits 404
Hehe, I don't really want to rely on other software to do it.
I just want to use batch files~~ Hehe
Floor4 3742668 Posted 2006-04-25 21:04
荣誉版主 Posts 718 Credits 2,013
Look through it carefully; this was posted before.
Method 1:

This can display the content starting from the fourth line. If you only want to display the fourth line, you can append &call or &exit at the end.
Method 2:

Analyze the specific situation specifically.
Floor5 kcdsw Posted 2006-04-25 22:28
中级用户 Posts 179 Credits 404
Thanks for your answer.
Hehe, I already looked through all those, and I also wrote one myself.
It's just that the efficiency isn't very high (that's how it feels to me),
because every file that needs to be analyzed is over 50MB, and I want to be lazy too~~
What I'm thinking is whether it can directly read the second line to save time.

Suddenly I got a new idea. After reading your reply, I was thinking: we use for to search for a certain string, and for needs to traverse, but my string only needs to be found once and that's OK. Can some other command be used, or can it exit the for statement after finding it? My thoughts are a bit messy for now~~~ Please advise.

[ Last edited by kcdsw on 2006-4-25 at 22:33 ]
Floor6 3742668 Posted 2006-04-25 22:42
荣誉版主 Posts 718 Credits 2,013
Read findstr /? a few more times; I hope you can figure out the method yourself.
The reason I gave the first plan is exactly because the first one can skip the first three lines and then end. Just looking at other people's stuff won't improve you much, so think more yourself.
Both methods can improve efficiency with only slight modifications.
Oh right, pay attention to the {"regular expressions" section} + {the "/n" parameter section} in findstr. If you understand these two parts, you can easily hit whatever target you point at.
Floor7 zhangxue Posted 2006-04-25 22:48
初级用户 Posts 82 Credits 183
Dos doesn't support for /f, does it?
Floor8 kcdsw Posted 2006-04-25 22:48
中级用户 Posts 179 Credits 404
I got confused.


ok, going to sleep~~ thank you~~

[ Last edited by kcdsw on 2006-4-26 at 14:02 ]
Floor9 kcdsw Posted 2006-04-26 00:12
中级用户 Posts 179 Credits 404
I'll change the rest tomorrow. The second time it has to query inside the xml, but since the file is small, it doesn't feel like it affects the speed.

At first I used type redirection and used find to search.
Later, when testing findstr, I discovered its pattern and the speed improved greatly. It can finish in 1 second; before that it had to be measured in minutes.
Alright, work will be a lot easier from now on.

[ Last edited by kcdsw on 2006-4-26 at 00:14 ]

Attachments
新建 BMP 图像 (2).JPG (91.51 KiB)
Floor10 无奈何 Posted 2006-04-26 00:16
荣誉版主 Posts 356 Credits 1,338
If you're after efficiency, you can try sed

sed -n "2{p;q}" file.txt

It can display the second line of the file.
sed download:http://www.student.northpark.edu/pemente/sed/gsed407x.zip
Floor11 kcdsw Posted 2006-04-26 15:41
中级用户 Posts 179 Credits 404
Found a bug

Correction



The idea is to use the $ in findstr to delimit the line that needs to be searched at the end.
Because the characters I need only appear on the second line, the efficiency is still acceptable.
But when using the same command to search in an xml file, it went wrong.
In the end I still used type redirection. Fortunately the xml files are not over 20kb, so that's how it is.

I made some simple optimizations to the program. Let's leave it like this for now. Thanks to Wunaihe in the previous post and the brothers above him too~~

[ Last edited by kcdsw on 2006-4-26 at 15:46 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023