[原创]为感谢这里的朋友一年来对我的支持,特献grep的使用二

发表于:2007-06-09来源:作者:点击数: 标签:
grep的使用二 #ls-l|grep^d(仅列出当前目录下的所有目录) drwxr-xr-x2rootother51211月2522:41ldap # #ls-l|grep^[^d](仅列出当前目录下的所有文件) -rw-r--r--1rootother498711月2523:22grep.log -rw-r--r--1rootother011月2622:34grep.log2 -rw-r--r--

grep的使用二
# ls -l | grep "^d"(仅列出当前目录下的所有目录)
drwxr-xr-x   2 root     other        512 11月 25 22:41 ldap

# ls -l | grep"^[^d]"(仅列出当前目录下的所有文件)
-rw-r--r--   1 root     other       4987 11月 25 23:22 grep.log
-rw-r--r--   1 root     other          0 11月 26 22:34 grep.log2
-rw-r--r--   1 root     other        267 11月 19 19:37 ifconfig
#
# ls -l|grep "^d.....x..x"(仅列出当前目录下符合“d.....x..x”权限的目录)
drwxr-xr-x   2 root     other        512 11月 25 22:41 ldap

# grep "mailsrv" /etc/passwd(抽出/etc/passwd中“mailsrv”的用户信息)
mailsrv:x:101:3:iplanet mail user:/iplanet/server5/bin/msg/admin/bin:/bin/sh

# grep "mailsrv" /etc/passwd >mailuser.log
# (抽出/etc/passwd中“mailsrv”的用户信息输出到一个文件(mailsrv.log)中)
# more mailuser.log
mailsrv:x:101:3:iplanet mail user:/iplanet/server5/bin/msg/admin/bin:/bin/sh

# ps -ef|grep telnet(在显示的进程中抽出“telnet”进程)
    root   321   165  0 22:29:33 ?        0:00 in.telnetd
    root   638   434  0 23:35:38 pts/1    0:00 grep telnet
# ps -ef|grep telnet | grep -v grep (在显示的进程中抽出“telnet”进程;并丢弃ps中的grep进程)
    root   321   165  0 22:29:33 ?        0:00 in.telnetd

# ps -ef|grep -v telnet(将抽出除“telnet”之外的所有进程)
# cat zhao.conf(再来看一下我们使用的文件内容)
48      Dec     3BC1997      LPSX  68.00 LVX2A    138
483     Sept    5AP1996      USP   65.00 LVX2C    189
47      Oct     3ZL1998      LPSX  43.00 KVM9D    512
219     dec     2CC1999      CAD   23.00 PLV2C    68
484     nov     7PL1996      CAD   49.00 PLV2C    234
487     may     5PA1998      USP   37.00 KVM9D    644
471     May     7Zh1999      UDP   37.00 KV30D   643
# egrep "(3ZL|2CC)" zhao.conf(使用egrep来抽取文件(zhao.conf)中前三个字符匹配“3ZL”或“2CC”的行)
47          Oct     3ZL1998      LPSX  43.00 KVM9D    512
219         dec     2CC1999      CAD   23.00 PLV2C    68
# grep "48" zhao.conf |wc(使用grep抽取文件(zhao.conf)中前两个字符匹配“48”的行,并统计出有几行匹配,有多少个
字,这些字占用多少字节的空间)
       4      28     224
在UNIX中字处理是一件很烦琐的事情,但这些字处理工具给我们带来了很大的方便;这里grep、egrep(扩展grep,在一些UNIX中
也存在)仅仅是一种工具。但其能灵活的抽出你需要的东东。它将随着你对UNIX的理解程度,逐步变成你手头不可缺少的一个工具
其在shell编程中同样具有举足轻重的位置。grep、egrep和其他字处理工具的组合使用更为灵活、深澳!谢谢!sunnycn


 zat 回复于:2002-11-27 10:07:24
好~!!

 syisyi 回复于:2002-12-01 20:15:30
UP

 YT 回复于:2002-12-01 21:13:28
看不懂,好。。
支持!

 tigerbrother 回复于:2002-12-03 12:03:57
狂好。

 travis 回复于:2002-12-06 11:52:33
太好了

 小淼。烟 回复于:2002-12-06 17:08:53
这个图片好漂亮!

就不知是不是你!

:) :em35: 

 lyh728 回复于:2002-12-06 19:04:04
hao

 YT 回复于:2002-12-07 05:54:30
再支持一下,依然看不懂中。。。。。

 foreverjj 回复于:2003-09-18 16:12:38
支持

 sparkzcl 回复于:2004-05-12 09:57:34
very good

 truelsm 回复于:2004-09-02 14:37:47
比较有用,!谢谢!

 truelsm 回复于:2004-09-02 14:38:00
比较有用,!谢谢!

 mymanunited 回复于:2004-11-09 08:57:42
hao,xieixe

 fwizard 回复于:2004-11-09 09:55:06
支持原创

 swy911 回复于:2005-08-08 16:44:11
谢谢!!

 IT_boy 回复于:2005-08-10 11:53:19
UP

原文转自:http://www.ltesting.net