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-08-09 10:29
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] findstr: find lines that start with [ and end with ] View 1,984 Replies 17
Original Poster Posted 2008-08-01 16:03 ·  中国 四川 德阳 电信
初级用户
Credits 96
Posts 45
Joined 2007-03-20 06:24
19-year member
UID 82322
Gender Male
Status Offline
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 ]
Floor 2 Posted 2008-08-01 16:37 ·  中国 北京 光环新网
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 3 Posted 2008-08-01 16:49 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Floor 4 Posted 2008-08-01 17:13 ·  中国 北京 联通
社区乞丐
Credits -61
Posts 37
Joined 2008-04-19 17:10
18-year member
UID 116329
Gender Male
Status Offline

findstr /r "^\$" 123.txt


In the FINDSTR command, are metacharacters in regular expressions, so you must use \ to escape them into literal characters
Floor 5 Posted 2008-08-01 17:17 ·  中国 四川 德阳 电信
初级用户
Credits 96
Posts 45
Joined 2007-03-20 06:24
19-year member
UID 82322
Gender Male
Status Offline
Thanks to the poster above.
Floor 6 Posted 2008-08-01 17:19 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by FQ at 2008-8-1 05:13 PM:

findstr /r "^\$" 123.txt


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.
Floor 7 Posted 2008-08-01 17:26 ·  中国 四川 德阳 电信
初级用户
Credits 96
Posts 45
Joined 2007-03-20 06:24
19-year member
UID 82322
Gender Male
Status Offline
I agree with the poster above
Floor 8 Posted 2008-08-01 17:27 ·  中国 四川 德阳 电信
初级用户
Credits 96
Posts 45
Joined 2007-03-20 06:24
19-year member
UID 82322
Gender Male
Status Offline
Why can't it display the last line [12345]?
Floor 9 Posted 2008-08-01 17:28 ·  中国 北京 联通
社区乞丐
Credits -61
Posts 37
Joined 2008-04-19 17:10
18-year member
UID 116329
Gender Male
Status Offline
Don't just talk about my code, look at what your own code is saying too

aaa[dddd]]
Floor 10 Posted 2008-08-01 17:29 ·  中国 北京 联通
社区乞丐
Credits -61
Posts 37
Joined 2008-04-19 17:10
18-year member
UID 116329
Gender Male
Status Offline
As long as your last line has a carriage return and line feed, my code is enough
Floor 11 Posted 2008-08-01 17:39 ·  中国 四川 德阳 电信
初级用户
Credits 96
Posts 45
Joined 2007-03-20 06:24
19-year member
UID 82322
Gender Male
Status Offline
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.
Floor 12 Posted 2008-08-01 19:59 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
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
Floor 13 Posted 2008-08-02 08:29 ·  中国 北京 联通
社区乞丐
Credits -61
Posts 37
Joined 2008-04-19 17:10
18-year member
UID 116329
Gender Male
Status Offline
Sigh, the key point is that it does display it
Floor 14 Posted 2008-08-02 10:43 ·  中国 四川 德阳 电信
初级用户
Credits 96
Posts 45
Joined 2007-03-20 06:24
19-year member
UID 82322
Gender Male
Status Offline
Originally posted by s11ss at 2008-8-1 04:49 PM:
findstr ^$

It really is a bit wrong. I didn't notice this point at first either. If there are characters before
Floor 15 Posted 2008-08-02 10:48 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
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
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Forum Jump: