LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1271|回复: 2

关于grep中的匹配以某某开头的过滤不好用

[复制链接]
发表于 2008-11-25 03:56:55 | 显示全部楼层 |阅读模式
RT!

查找系统中testuser_m开头的用户


yzhkpli@ibexserver:/opt$ sudo grep '\<testuser_m' /etc/passwd
testuser_mike:x:1003:1003::/home/testuser_john:/bin/sh
yzhkpli@ibexserver:/opt$

但是查找系统中以testuser_john开头的用户名:
yzhkpli@ibexserver:/opt$ sudo grep '\<testuser_john' /etc/passwd
testuser_john:x:1001:1001::/home/testuser_john:/bin/sh
testuser_john2:x:1002:1002::/home/testuser_john:/bin/sh
testuser_mike:x:1003:1003::/home/testuser_john:/bin/sh

注意:怎么把testuser_mike用户也找出来了??
发表于 2008-11-25 09:11:16 | 显示全部楼层
也许你想了解一下 grep 中 '^' 的含义,然后再去骂 grep 不好用
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-11-25 15:35:31 | 显示全部楼层
话说原来\<是查找以指定匹配为开头的单词,还以为是行呢~~~谢谢提醒。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表