免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: admirer
打印 上一主题 下一主题

[转贴]经常使用的正则表达式举例  关闭 [复制链接]

论坛徽章:
0
21 [报告]
发表于 2006-01-18 14:14 |只看该作者
ls -a | grep '^\.'

也可以嘛,不用那么麻烦.

论坛徽章:
0
22 [报告]
发表于 2006-03-18 21:18 |只看该作者
ls -a | grep ^\. 和 ls -a | grep "^\."的结果为什么不一样?
前者列出了所有的文件,后者只是列出了以 . 开头的文件

论坛徽章:
0
23 [报告]
发表于 2006-03-25 06:15 |只看该作者
原帖由 netzh 于 2003-10-29 19:29 发表
纠正一个错误
    ^[the]对以the开头行
应该把[]去掉才对,test

# touch {thefile,thfile,tfile1}
# ls -1|grep ^[the]
# ls -1|grep ^the


$ ls
tfile    thefile  thfile
$ ls -l |grep ^the
$ ls -l |grep ^[the]
total 0
$ oslevel
5.2.0.0
$ whatshell
ksh: whatshell:  not found.
$

我的以上的结果是什么原因,好郁闷啊.

论坛徽章:
0
24 [报告]
发表于 2006-03-25 06:29 |只看该作者
我明白了,谢谢大家

$ ls
tfile    thefile  thfile
$ ls |grep ^the
thefile
$ ls -l |grep ^the
$ ls -1 |grep ^the
thefile
$ ls -1 |grep ^[the]
tfile
thefile
thfile
$

论坛徽章:
0
25 [报告]
发表于 2006-03-25 09:31 |只看该作者
原帖由 liuyunxiaoyan 于 2005-7-26 15:06 发表
[may|MAY] 才能表示包含may大写或小写字母的行.

试了一下这个说法好像也不对吧.
zxme:/export/home/zxme/wanjm>touch {may,MAY,mAy}
zxme:/export/home/zxme/wanjm>ls | grep "[may|MAY]"
MAY
a.out
mAy
may
mq_create.c

要找出含有may或者MAY的应该怎么写呢?

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
26 [报告]
发表于 2006-04-07 16:39 |只看该作者
ls -a | awk '/^\./'   
现学现卖...

论坛徽章:
0
27 [报告]
发表于 2006-05-15 21:24 |只看该作者
我也来一个
ls -a | grep '^\.[^.]' | more

论坛徽章:
0
28 [报告]
发表于 2006-05-15 21:57 |只看该作者
原帖由 admirer 于 2003-11-3 20:57 发表
ls -a  | sed -n '/^\./p'

没显示:
#touch .file
ls -al
有.file
#ls -a  | sed -n '/^\./p'
#
sed是3.02

论坛徽章:
0
29 [报告]
发表于 2006-05-15 22:26 |只看该作者
对不起,弄错了,我把"alias l=ls -al"了。
结果是正确的。

论坛徽章:
0
30 [报告]
发表于 2006-07-07 14:13 |只看该作者
原帖由 sickcat2004 于 2006-5-15 21:24 发表
我也来一个
ls -a | grep '^\.[^.]' | more

其实还是有些区别的,看下面我的测试:
  1. [root@test160 tmp]# ls -a |awk '/^\./'
  2. .
  3. ..
  4. .font-unix
  5. .gdm_socket
  6. .ICE-unix
  7. .X0-lock
  8. .X11-unix
  9. [root@test160 tmp]# ls -a |grep '^\.[^.]'|more
  10. .font-unix
  11. .gdm_socket
  12. .ICE-unix
  13. .X0-lock
  14. .X11-unix
  15. [root@test160 tmp]# ls -a |sed -n '/^\./p'
  16. .
  17. ..
  18. .font-unix
  19. .gdm_socket
  20. .ICE-unix
  21. .X0-lock
  22. .X11-unix
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP