免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 1838 | 回复: 11
打印 上一主题 下一主题

grep "^string"的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-04-13 18:34 |只看该作者 |倒序浏览
[root@m7 tmp]# cat tmp-cfg

Section "Monitor"
        Identifier   "Monitor0"
        HorizSync    30.5 - 100.9
        VertRefresh  60.0 - 120.0
EndSection

[root@m7 tmp]# grep "^[]*Identifier" tmp-cfg
[root@m7 tmp]#
没有结果,为啥? 本意是选出
       Identifier   "Monitor0"
这一行.

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2004-04-13 18:42 |只看该作者

grep "^string"的问题

应该是grep版本问题,我的可以:
  1. admirer /tmp/aa # grep --version
  2. grep (GNU grep) 2.4
复制代码
  1. grep "^[:space:]*Identifier" file
  2. Identifier "Monitor0"
复制代码

论坛徽章:
0
3 [报告]
发表于 2004-04-13 18:50 |只看该作者

grep "^string"的问题

用cat -A看看,应该是tab,所以:

  1. grep "^[        ]Identifier" file
复制代码

论坛徽章:
0
4 [报告]
发表于 2004-04-13 18:57 |只看该作者

grep "^string"的问题

[quote]原帖由 "bjgirl"][/quote 发表:

[root@m7 tmp]# cat -A tmp-cfg
Section "ServerLayout"$
^IIdentifier     "Default Layout"$
^IScreen         "Screen0"$
^IInputDevice    "Mouse0" "CorePointer"$
^IInputDevice    "Keyboard0" "CoreKeyboard"$
^IInputDevice    "DevInputMice" "AlwaysCore"$
^IOption "RandR" "off"$
EndSection$
$
[root@m7 tmp]# grep -V
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@m7 tmp]#

论坛徽章:
0
5 [报告]
发表于 2004-04-13 18:58 |只看该作者

grep "^string"的问题

NULL

论坛徽章:
0
6 [报告]
发表于 2004-04-13 19:02 |只看该作者

grep "^string"的问题

  1. cat XF86Config|grep "^[ ]Id"
  2.         Identifier     "Default Layout"
  3.         Identifier  "Keyboard0"
  4.         Identifier  "Mouse0"
  5.         Identifier  "DevInputMice"
  6.         Identifier   "Monitor0"
  7.         Identifier  "Videocard0"
  8.         Identifier "Screen0"
复制代码
ps:grep --version
grep (GNU grep) 2.5.1

论坛徽章:
0
7 [报告]
发表于 2004-04-13 19:22 |只看该作者

grep "^string"的问题

原帖由 "bjgirl" 发表:
s:grep --version
grep (GNU grep) 2.5.1

  1. [root@m7 tmp]# hexdump  -C tmp-cfg
  2. 00000000  53 65 63 74 69 6f 6e 20  22 53 65 72 76 65 72 4c  |Section "ServerL|
  3. 00000010  61 79 6f 75 74 22 0a 09  49 64 65 6e 74 69 66 69  |ayout"..Identifi|
  4. 00000020  65 72 20 20 20 20 20 22  44 65 66 61 75 6c 74 20  |er     "Default |
  5. 00000030  4c 61 79 6f 75 74 22 0a  09 53 63 72 65 65 6e 20  |Layout"..Screen |
复制代码

中间是个tab键.info了grep一把,没有\t这种用法所以
grep "^[ \t]*Identifier"
不对,应该为


  1. [root@m7 tmp]# grep "^[[:space:]]*Identifier" tmp-cfg
  2.         Identifier     "Default Layout"
  3. [root@m7 tmp]#
复制代码

而不是:

  1. [root@m7 tmp]# grep "^[:space:]*Identifier" tmp-cfg
  2. [root@m7 tmp]#
复制代码


ft

论坛徽章:
0
8 [报告]
发表于 2004-04-13 19:27 |只看该作者

grep "^string"的问题

晕~~~,^I就是tab呀! 直接按tab不就可以

论坛徽章:
0
9 [报告]
发表于 2004-04-13 19:31 |只看该作者

grep "^string"的问题

[quote]原帖由 "bjgirl"]晕~~~,^I就是tab呀! 直接按tab不就可以 [/quote 发表:


  1. [root@m7 tmp]# grep "^[
  2.                        ^你说是在这里按tab键吗?没有反应啊?
复制代码

论坛徽章:
0
10 [报告]
发表于 2004-04-13 19:37 |只看该作者

grep "^string"的问题

grep "^[按tab]...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP