Board logo

标题: 大家帮我看看这个p错在哪里? [打印本页]

作者: anqing     时间: 2007-2-11 22:51    标题: 大家帮我看看这个p错在哪里?

@echo off

for /f "delims=" %%i in ('findstr /x /b "我 你 有" test1.txt') do echo %%i

pause


本意,是想查找txt文件中,含 有“我”或“你”,或“有”这三个字,只要txt中任意一行,含有以上的三个字中的一个,就显示出来
??
作者: ccwan     时间: 2007-2-11 23:22
再想办法吧。

[ Last edited by ccwan on 2007-2-11 at 11:30 PM ]
作者: anqing     时间: 2007-2-11 23:38
有知道的,帮我改一下,我是弄不出来了

作者: anqing     时间: 2007-2-12 00:53
@echo off
set a=我
set b=你
set c=有
for /f "delims=" %%i in ('findstr /i %a% test1.txt') do echo %%i
for /f "delims=" %%i in ('findstr /i %b% test1.txt') do echo %%i
for /f "delims=" %%i in ('findstr /i %c% test1.txt') do echo %%i
pause
是这样的,但好像代码太长了,能不能精简一下?
在有,我想在显示的句子前面加一个它所在txt中的行号,如何能做到?
作者: ccwan     时间: 2007-2-12 01:00
你这样的话,输出的内容和原来文件内容的顺序就不一样了,不是吗?不考虑顺序吗?
作者: anqing     时间: 2007-2-12 01:11
不考虑,只要能输出句子,和它所在行的行号,重复也没有关系
txt文件内容如下‘
dim a
set a=CreateObject("Wscript.Shell")
Do
a.run "11.exe"
Wscript.Slleep 60000
Loop
最美的十大精典爱情句子

    1) I love you not because of who you are, but because of who I am when I am with you.
   
    我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。

    2) No man or woman is worth your tears, and the one who is, won't make you cry.
   
     没有人值得你流泪,值得让你这么做的人不会让你哭泣。

    3) The worst way to miss someone is to be sitting right beside them knowing you can't have them.
   
    失去某人,最糟糕的莫过于,他近在身旁,却犹如远在天边。

    4) Never frown, even when you are sad, because you never know who is falling in love with your smile.
   
    纵然伤心,也不要愁眉不展,因为你不知是谁会爱上你的笑容。

    5) To the world you may be one person, but to one person you may be the world.

    对于世界而言,你是一个人;但是对于某个人,你是他的整个世界。

    6) Don‘t waste your time on a man/woman, who isn't willing to waste their time on you.

    不要为那些不愿在你身上花费时间的人而浪费你的时间。

    7) Just because someone doesn't love you the way you want them to, doesn't mean they don't love you with all they have.

    爱你的人如果没有按你所希望的方式来爱你,那并不代表他们没有全心全意地爱你。

    8) Don't try so hard, the best things come when you least expect them to.

    不要着急,最好的总会在最不经意的时候出现。

    9) Maybe God wants us to meet a few wrong people before meeting the right one, so that when we finally meet the person, we will know how to be grateful.

    在遇到梦中人之前,上天也许会安排我们先遇到别的人;在我们终于遇见心仪的人时,便应当心存感激。

    10) Don't cry because it is over, smile because it happened.

    不要因为结束而哭泣,微笑吧,为你的曾经拥有。
如何能过滤掉空格,也是个问题呀
作者: ccwan     时间: 2007-2-12 01:13
既然不要原来顺序,还要行数?
如不要行数,我有代码给你
作者: vkill     时间: 2007-2-12 01:16
语法就不正确怎么感觉
作者: vkill     时间: 2007-2-12 01:17
还不如直接type .txt|findstr
作者: anqing     时间: 2007-2-12 01:24
要原来的顺序,要不,怎么确定它的行号?
这个p的意思是,查找特定的”字“,然后显示出,它所在的语句,并显示出语句在txt中的行号。
作者: ccwan     时间: 2007-2-12 02:01
版主不是给过你代码吗?在群里。那个是最简单有效的了。
作者: slore     时间: 2007-2-12 02:18
@echo off
for /F "tokens=1,2,3 delims= " %%i in ("我 你 有") do (
findstr %%i 1.txt
findstr %%j 1.txt
findstr %%k 1.txt
)



上面也麻烦了

@echo off
findstr "我" 1.txt &&findstr "你" 1.txt &&findstr "有" 1.txt
pause
作者: slore     时间: 2007-2-12 02:20
'findstr /x /b "我 你 有" test1.txt'

findstr的连续查询貌似不支持中文!!!!

findstr  "you love 我 cry" test1.txt
就可以看出,you love cry的可以显示,但是我的不能显示出来.
作者: ccwan     时间: 2007-2-12 02:27
^_^


@echo off
for /f "delims=" %%i in ('findstr /n .* test1.txt') do echo %%i>>test.txt
findstr /i "我 你 有" test.txt
del test.txt&pause
namejmWengierdoscctv
作者: slore     时间: 2007-2-12 02:29
忘了/i 了怪不得

你们为什么搞那么麻烦?


findstr /i "我 你 有" test1.txt
作者: ccwan     时间: 2007-2-12 02:31

作者: slore     时间: 2007-2-12 02:32
中文的还要用忽略大小写才能出来=.=不知道算不算bug
作者: anqing     时间: 2007-2-12 02:33
感谢
作者: slore     时间: 2007-2-12 02:33
哦,没看到后面.
作者: slore     时间: 2007-2-12 02:36


  Quote:
Originally posted by ccwan at 2007-2-11 13:31:
,[/col ...

这样呢>
findstr /i /n " " 1.txt
作者: anqing     时间: 2007-2-12 02:38
有一行空格行,没有被计算在内呀
比如,
dim a
set a=CreateObject("Wscript.Shell")
Do
a.run "11.exe"
Wscript.Slleep 60000
Loop
最美的十大精典爱情句子

    1) I love you not because of who you are, but because of who I am when I am with you.
   
    我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉 这句如果算空格行的话,应该是12行?
我想计算空格行在内,应该如何做?
findstr /i "我 你 有" test3.txt
我想查找只带三字其中一字的行,然后显示输出

作者: slore     时间: 2007-2-12 03:31
没错呀
附件 1: 1.JPG (2007-2-12 03:31, 53.18 K, 下载附件所需积分 1点 ,下载次数: 1)



作者: oilio     时间: 2007-2-12 04:59
这十大句子我也喜欢,个别看过,收藏了。也来学习学习。这样的帖子好,既可以学知识,又可以学到哲理的东西。
作者: anqing     时间: 2007-2-12 06:04
没有计算空格行呀?
作者: anqing     时间: 2007-2-12 06:06
dim a
set a=CreateObject("Wscript.Shell")
Do
a.run "11.exe"
Wscript.Slleep 60000
Loop
最美的十大精典爱情句子

    1) I love you not because of who you are, but because of who I am when I am with you.
   
    我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。

    2) No man or woman is worth your tears, and the one who is, won't make you cry.
   
     没有人值得你流泪,值得让你这么做的人不会让你哭泣。

    3) The worst way to miss someone is to be sitting right beside them knowing you can't have them.
作者: anqing     时间: 2007-2-12 06:07
哪我在记事本,为什么显示的11行,却是第12行呢?
作者: anqing     时间: 2007-2-12 06:09
我用写字板打开了,确实是11行,看来,我的记事本,是不是有些毛病了?
作者: anqing     时间: 2007-2-12 12:59
cc明天给你加分,今天不好意思了?加完了,谢谢!
作者: bbq123bbq     时间: 2007-2-12 13:54
for /f %%a in ('findstr /i "我我 你 有" test1.txt') do echo %%a
作者: namejm     时间: 2007-2-12 14:36
  用 findstr 查找含有中文字符的几个字符串的时候,/i 虽然能准确匹配中文字符,但是,却会忽略英文的大小写。如果对大小写很介意的话,那就把 /i 换成 /r 吧。这可能是 findstr 查找中文字符串的一个bug,也可能是 /r 开关存在的理由,目前还不得而知。
作者: slore     时间: 2007-2-12 17:42


  Quote:
Originally posted by namejm at 2007-2-12 01:36:
  用 findstr 查找含有中文字符的几个字符串的时候,/i 虽然能准确匹配中文字符,但是,却会忽略英文的大小写。如果对大小写很介意的话,那就把 ...

d:\slorelee\桌面>findstr /i /n "我 你 dIm a. 有" 1.txt
1:dim a
4:a.run "11.exe"
11:    我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。
15:     没有人值得你流泪,值得让你这么做的人不会让你哭泣。

d:\slorelee\桌面>findstr /i /n "我 你 dIm A. 有" 1.txt
1:dim a
4:a.run "11.exe"
11:    我爱你,不是因为你是一个怎样的人,而是因为我喜欢与你在一起时的感觉。
15:     没有人值得你流泪,值得让你这么做的人不会让你哭泣。

d:\slorelee\桌面>

?????????正常啊
作者: namejm     时间: 2007-2-12 22:30
  别忘了,/i 是忽略英文大小写的开关,dIm A 不完全等同 dim a 。
作者: slore     时间: 2007-2-13 02:46


  Quote:
Originally posted by namejm at 2007-2-12 09:30:
  别忘了,/i 是忽略英文大小写的开关,dIm A 不完全等同 dim a 。

引用明白你说的了=。=

/I的作用就是忽略大小写

你的意思如果不想忽略的话用了这个参数就……

我以为你说的如果用了这个参数,“你 有 我 DIm A”里面的忽略大小写就不能用了呢。。。