| 论坛注册| 加入收藏 | 设为首页| RSS
Google
您当前的位置:首页 > Linux频道 > Linux开发区 > SHELL

shell学习—关于grep的简单使用

时间:2007-11-20 10:42:36  来源:Linux联盟收集整理  作者:
grep是在shell中比较常用的工具,常用的选项有:T2CLinux联盟
-c只输出匹配行的计数,例如:T2CLinux联盟
T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -c "get" /usr/include/ncurses.hT2CLinux联盟
57T2CLinux联盟
T2CLinux联盟
-i不区分大小写(只适用于单字符),例如:T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -i "GET" /usr/include/ncurses.hT2CLinux联盟
#include <wchar.h>              /* ...to get mbstate_t, etc. */T2CLinux联盟
#ifdef NCURSES_WGETCH_EVENTST2CLinux联盟
extern NCURSES_EXPORT(int) wgetch_events(WINDOW *, _nc_eventlist *);    /* experimental */T2CLinux联盟
extern NCURSES_EXPORT(int) wgetnstr_events(WINDOW *,char *,int,_nc_eventlist *);/* experimental */T2CLinux联盟
#endif /* NCURSES_WGETCH_EVENTS */T2CLinux联盟
extern NCURSES_EXPORT(int) attr_get (attr_t *, short *, void *);        /* generated */T2CLinux联盟
extern NCURSES_EXPORT(chtype) getbkgd (WINDOW *);                       /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) getch (void);                                /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) getnstr (char *, int);                       /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) getstr (char *);                             /* generated */T2CLinux联盟
extern NCURSES_EXPORT(WINDOW *) getwin (FILE *);                        /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(int) mvgetch (int, int);                          /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) mvgetnstr (int, int, char *, int);           /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) mvgetstr (int, int, char *);                 /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) mvwgetch (WINDOW *, int, int);               /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) mvwgetnstr (WINDOW *, int, int, char *, int);       /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) mvwgetstr (WINDOW *, int, int, char *);      /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) tigetflag (NCURSES_CONST char *);            /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(int) tigetnum (NCURSES_CONST char *);             /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(char *) tigetstr (NCURSES_CONST char *);          /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(int) ungetch (int);                               /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(int) wattr_get (WINDOW *, attr_t *, short *, void *);    /* generated */T2CLinux联盟
extern NCURSES_EXPORT(int) wgetch (WINDOW *);                           /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(int) wgetnstr (WINDOW *,char *,int);              /* implemented */T2CLinux联盟
extern NCURSES_EXPORT(int) wgetstr (WINDOW *, char *);                  /* generated */T2CLinux联盟
#define wgetstr(w, s)           wgetnstr(w, s, -1)T2CLinux联盟
#define getnstr(s, n)           wgetnstr(stdscr, s, n)T2CLinux联盟
#define gettmode()T2CLinux联盟
#define getyx(win,y,x)          (y = (win)?(win)->_cury:ERR, x = (win)?(win)->_curx:ERR)T2CLinux联盟
#define getbegyx(win,y,x)       (y = (win)?(win)->_begy:ERR, x = (win)?(win)->_begx:ERR)T2CLinux联盟
#define getmaxyx(win,y,x)       (y = (win)?((win)->_maxy + 1):ERR, x = (win)?((win)->_maxx + 1):ERR)T2CLinux联盟
#define getparyx(win,y,x)       (y = (win)?(win)->_pary:ERR, x = (win)?(win)->_parx:ERR)T2CLinux联盟
#define getsyx(y,x) do { if(newscr->_leaveok) (y)=(x)=-1; \T2CLinux联盟
                         else getyx(newscr,(y),(x)); \T2CLinux联盟
#define getattrs(win)           ((win)?(win)->_attrs:A_NORMAL)T2CLinux联盟
#define getcurx(win)            ((win)?(win)->_curx:ERR)T2CLinux联盟
#define getcury(win)            ((win)?(win)->_cury:ERR)T2CLinux联盟
#define getbegx(win)            ((win)?(win)->_begx:ERR)T2CLinux联盟
#define getbegy(win)            ((win)?(win)->_begy:ERR)T2CLinux联盟
#define getmaxx(win)            ((win)?((win)->_maxx + 1):ERR)T2CLinux联盟
#define getmaxy(win)            ((win)?((win)->_maxy + 1):ERR)T2CLinux联盟
#define getparx(win)            ((win)?(win)->_parx:ERR)T2CLinux联盟
#define getpary(win)            ((win)?(win)->_pary:ERR)T2CLinux联盟
#define touchwin(win)           wtouchln((win), 0, getmaxy(win), 1)T2CLinux联盟
#define untouchwin(win)         wtouchln((win), 0, getmaxy(win), 0)T2CLinux联盟
#define attr_get(ap,cp,o)       wattr_get(stdscr,ap,cp,o)T2CLinux联盟
#define getch()                 wgetch(stdscr)T2CLinux联盟
#define getstr(str)             wgetstr(stdscr,str)T2CLinux联盟
#define mvwgetch(win,y,x)               (wmove(win,y,x) == ERR ? ERR : wgetch(win))T2CLinux联盟
#define mvwgetnstr(win,y,x,str,n)       (wmove(win,y,x) == ERR ? ERR : wgetnstr(win,str,n))T2CLinux联盟
#define mvwgetstr(win,y,x,str)          (wmove(win,y,x) == ERR ? ERR : wgetstr(win,str))T2CLinux联盟
#define mvgetch(y,x)                    mvwgetch(stdscr,y,x)T2CLinux联盟
#define mvgetnstr(y,x,str,n)            mvwgetnstr(stdscr,y,x,str,n)T2CLinux联盟
#define mvgetstr(y,x,str)               mvwgetstr(stdscr,y,x,str)T2CLinux联盟
#define getbkgd(win)                    ((win)->_bkgd)T2CLinux联盟
#define wattr_get(win,a,p,opts)         ((void)((a) != 0 && (*(a) = (win)->_attrs)), \T2CLinux联盟
* Pseudo-character tokens outside ASCII range.  The curses wgetch() functionT2CLinux联盟
extern NCURSES_EXPORT(int) getmouse (MEVENT *);T2CLinux联盟
extern NCURSES_EXPORT(int) ungetmouse (MEVENT *);T2CLinux联盟
[liuqi@ljjk liuqi]$T2CLinux联盟
T2CLinux联盟
作一个对比:T2CLinux联盟
T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -c -i "GET" /usr/include/ncurses.hT2CLinux联盟
59T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -c  "GET" /usr/include/ncurses.hT2CLinux联盟
2T2CLinux联盟
[liuqi@ljjk liuqi]$T2CLinux联盟
T2CLinux联盟
-h查询多个文件时不显示文件名,例如:T2CLinux联盟
T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -c "get" /usr/include/*es.hT2CLinux联盟
/usr/include/aliases.h:4T2CLinux联盟
/usr/include/curses.h:57T2CLinux联盟
/usr/include/features.h:3T2CLinux联盟
/usr/include/gdk_imlib_types.h:0T2CLinux联盟
/usr/include/Imlib_types.h:0T2CLinux联盟
/usr/include/inttypes.h:0T2CLinux联盟
/usr/include/lber_types.h:0T2CLinux联盟
/usr/include/ldap_features.h:1T2CLinux联盟
/usr/include/libmng_types.h:10T2CLinux联盟
/usr/include/ncurses.h:57T2CLinux联盟
/usr/include/nl_types.h:2T2CLinux联盟
/usr/include/values.h:0T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -h -c "get" /usr/include/*es.hT2CLinux联盟
4T2CLinux联盟
57T2CLinux联盟
3T2CLinux联盟
0T2CLinux联盟
0T2CLinux联盟
0T2CLinux联盟
0T2CLinux联盟
1T2CLinux联盟
10T2CLinux联盟
57T2CLinux联盟
2T2CLinux联盟
0T2CLinux联盟
[liuqi@ljjk liuqi]$T2CLinux联盟
T2CLinux联盟
T2CLinux联盟
查询多文件时只输出包含匹配字符的文件名,例如:T2CLinux联盟
T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -h -c "get" /usr/include/*es.hT2CLinux联盟
4T2CLinux联盟
57T2CLinux联盟
3T2CLinux联盟
0T2CLinux联盟
0T2CLinux联盟
0T2CLinux联盟
0T2CLinux联盟
1T2CLinux联盟
10T2CLinux联盟
57T2CLinux联盟
2T2CLinux联盟
0T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -c "get" /usr/include/*es.hT2CLinux联盟
/usr/include/aliases.h:4T2CLinux联盟
/usr/include/curses.h:57T2CLinux联盟
/usr/include/features.h:3T2CLinux联盟
/usr/include/gdk_imlib_types.h:0T2CLinux联盟
/usr/include/Imlib_types.h:0T2CLinux联盟
/usr/include/inttypes.h:0T2CLinux联盟
/usr/include/lber_types.h:0T2CLinux联盟
/usr/include/ldap_features.h:1T2CLinux联盟
/usr/include/libmng_types.h:10T2CLinux联盟
/usr/include/ncurses.h:57T2CLinux联盟
/usr/include/nl_types.h:2T2CLinux联盟
/usr/include/values.h:0T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -h -c -l "get" /usr/include/*es.hT2CLinux联盟
/usr/include/aliases.hT2CLinux联盟
/usr/include/curses.hT2CLinux联盟
/usr/include/features.hT2CLinux联盟
/usr/include/ldap_features.hT2CLinux联盟
/usr/include/libmng_types.hT2CLinux联盟
/usr/include/ncurses.hT2CLinux联盟
/usr/include/nl_types.hT2CLinux联盟
[liuqi@ljjk liuqi]$T2CLinux联盟
T2CLinux联盟
-n只显示匹配行及行号,例如:T2CLinux联盟
T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -n "get" /usr/include/nl_types.hT2CLinux联盟
27:/* Value for FLAG parameter of `catgets' to say we want XPG4 compliance.  */T2CLinux联盟
44:extern char *catgets (nl_catd __catalog, int __set, int __number,T2CLinux联盟
[liuqi@ljjk liuqi]$T2CLinux联盟
T2CLinux联盟
-v显示不包含匹配文本的所由行,例如:T2CLinux联盟
T2CLinux联盟
[liuqi@ljjk liuqi]$ grep -v "get" /usr/include/nl_types.hT2CLinux联盟
/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.T2CLinux联盟
   This file is part of the GNU C Library.T2CLinux联盟
T2CLinux联盟
   The GNU C Library is free software; you can redistribute it and/orT2CLinux联盟
   modify it under the terms of the GNU Lesser General PublicT2CLinux联盟
   License as published by the Free Software Foundation; eitherT2CLinux联盟
   version 2.1 of the License, or (at your option) any later version.T2CLinux联盟
T2CLinux联盟
   The GNU C Library is distributed in the hope that it will be useful,T2CLinux联盟
   but WITHOUT ANY WARRANTY; without even the implied warranty ofT2CLinux联盟
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUT2CLinux联盟
   Lesser General Public License for more details.T2CLinux联盟
T2CLinux联盟
   You should have received a copy of the GNU Lesser General PublicT2CLinux联盟
   License along with the GNU C Library; if not, write to the FreeT2CLinux联盟
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MAT2CLinux联盟
   02111-1307 USA.  */T2CLinux联盟
T2CLinux联盟
#ifndef _NL_TYPES_HT2CLinux联盟
#define _NL_TYPES_H 1T2CLinux联盟
T2CLinux联盟
#include <features.h>T2CLinux联盟
T2CLinux联盟
/* The default message set used by the gencat program.  */T2CLinux联盟
#define NL_SETD 1T2CLinux联盟
T2CLinux联盟
#define NL_CAT_LOCALE 1T2CLinux联盟
T2CLinux联盟
T2CLinux联盟
__BEGIN_DECLST2CLinux联盟
T2CLinux联盟
/* Message catalog descriptor type.  */T2CLinux联盟
typedef void *nl_catd;T2CLinux联盟
T2CLinux联盟
/* Type used by `nl_langinfo'.  */T2CLinux联盟
typedef int nl_item;T2CLinux联盟
T2CLinux联盟
/* Open message catalog for later use, returning descriptor.  */T2CLinux联盟
extern nl_catd catopen (__const char *__cat_name, int __flag) __THROW;T2CLinux联盟
T2CLinux联盟
/* Return translation with NUMBER in SET of CATALOG; if not foundT2CLinux联盟
   return STRING.  */T2CLinux联盟
                      __const char *__string) __THROW;T2CLinux联盟
T2CLinux联盟
/* Close message CATALOG.  */T2CLinux联盟
extern int catclose (nl_catd __catalog) __THROW;T2CLinux联盟
T2CLinux联盟
__END_DECLST2CLinux联盟
T2CLinux联盟
#endif /* nl_types.h  */T2CLinux联盟
[liuqi@ljjk liuqi]$T2CLinux联盟
T2CLinux联盟
T2CLinux联盟
当然,也可以结合正则表达式使用grep来查找文件.T2CLinux联盟
其他详悉内容和使用方法用man可以查看得到
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目更新
栏目热门