中国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-09 09:29
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » [Help] findstr: find lines that start with [ and end with ]
Printable Version  1,980 / 17
Floor1 joyoustar Posted 2008-08-01 16:03
初级用户 Posts 45 Credits 96
As the title says, suppose text file 123.txt contains characters like the following
yiqiweiaoyunjiayou



]end title



abc
abcdef
I want to find the lines that start with and display them



The code findstr "^$" is not right. How should it be modified? Thanks!

[ Last edited by joyoustar on 2008-8-2 at 10:44 AM ]
Floor2 yishanju Posted 2008-08-01 16:37
银牌会员 Posts 1,357 Credits 1,488
Floor3 s11ss Posted 2008-08-01 16:49
银牌会员 Posts 566 Credits 2,098
Floor4 FQ Posted 2008-08-01 17:13
社区乞丐 Posts 37 Credits -61


In the FINDSTR command, are metacharacters in regular expressions, so you must use \ to escape them into literal characters
Floor5 joyoustar Posted 2008-08-01 17:17
初级用户 Posts 45 Credits 96
Thanks to the poster above.
Floor6 s11ss Posted 2008-08-01 17:19
银牌会员 Posts 566 Credits 2,098
Originally posted by FQ at 2008-8-1 05:13 PM:


In the FINDSTR command, are metacharacters in regular expressions, so you must use \ to escape them into literal characters

If the last line is just , rather than a blank line after it, then will not be displayed.
Floor7 joyoustar Posted 2008-08-01 17:26
初级用户 Posts 45 Credits 96
I agree with the poster above
Floor8 joyoustar Posted 2008-08-01 17:27
初级用户 Posts 45 Credits 96
Why can't it display the last line [12345]?
Floor9 FQ Posted 2008-08-01 17:28
社区乞丐 Posts 37 Credits -61
Don't just talk about my code, look at what your own code is saying too

aaa[dddd]]
Floor10 FQ Posted 2008-08-01 17:29
社区乞丐 Posts 37 Credits -61
As long as your last line has a carriage return and line feed, my code is enough
Floor11 joyoustar Posted 2008-08-01 17:39
初级用户 Posts 45 Credits 96
Originally posted by FQ at 2008-8-1 05:29 PM:
As long as your last line has a carriage return and line feed, my code is enough

Thanks, but it still feels like if I tweak it just a tiny bit more it would be perfect! Indeed, sometimes there is no newline at the end.
Brother s11ss's code is fine, but it would be best if something like "findstr "^\$" 123.txt" could be used.
Floor12 s11ss Posted 2008-08-01 19:59
银牌会员 Posts 566 Credits 2,098
Originally posted by FQ at 2008-8-1 05:28 PM:
Don't just talk about my code, look at what your own code is saying too

aaa

This line shouldn't be displayed in the first place, since it doesn't start with
Floor13 FQ Posted 2008-08-02 08:29
社区乞丐 Posts 37 Credits -61
Sigh, the key point is that it does display it
Floor14 joyoustar Posted 2008-08-02 10:43
初级用户 Posts 45 Credits 96
Originally posted by s11ss at 2008-8-1 04:49 PM:

It really is a bit wrong. I didn't notice this point at first either. If there are characters before
Floor15 quya Posted 2008-08-02 10:48
高级用户 Posts 172 Credits 558 From 江苏
Originally posted by joyoustar at 2008-8-1 05:39 PM:

Thanks, but it still feels like if I tweak it just a tiny bit more it would be perfect! Indeed, sometimes there is no newline at the end.
Brother s11ss's code is fine, but it would be best if something like "findstr "^\$" 123.txt" could be used.


If there's no carriage return line, then forcibly add one. I do that sometimes.

Before processing 123.txt, no matter whether its last line has a carriage return or not, first execute the following code:

echo. >>123.txt
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023