grep

GREP(1)                     General Commands Manual                    GREP(1)



å称
       grep, egrep, fgrep - ãã¿ã¼ã³ã«ãããããè¡ã表示ãã

æ¸å¼
       grep [ -[[AB] ]num ] [ -[CEFGVBchilnsvwx] ] [ -e ] pattern | -ffile ] [
       files...  ]

解説
       grep ã¯ã files ãæå®ããã¦ããã°ãã®ãã¡ã¤ã«ããããã¡ã¤ã«ãæå®ãã㦠ãªãã files
       ã®é¨åã« - ãæå®ãããå ´åã¯ãæ¨æºå¥åãèªã¿è¾¼ã¿ãè¡æ¯ã«ã
       æå®ãããã¿ã¼ã³ã«ãããããé¨åãå«ãã§ãããã©ãã調ã¹ãããã©ã«ãå
       ä½ã§ã¯ããããããè¡ã表示ãã¾ãã

       grep ã¯ã次ã®ãªãã·ã§ã³ã«ãã大ãã 3 ã¤ã®åä½ã«åããã¾ãã
       -G     ãã¿ã¼ã³ã¨ãã¦ãåºæ¬çãªæ£è¦è¡¨ç¾ãæ±ãã¢ã¼ããããã©ã«ãã§ãã
       -E     æ¡å¼µãããæ£è¦è¡¨ç¾ãæ±ãã¢ã¼ãã§ãããã ããæ¬ grep ã¯ãåºæ¬ã®æ£
              è¦è¡¨ç¾ã¨ãæ¡å¼µã®æ‐
              £è¦è¡¨ç¾ã«ã¯ã表è¨ä¸ã®éãã¯ããã¾ãããæ©è½çã«ã¯å·®ã¯ ããã¾ããã
       -F     ãã¿ã¼ã³ã¨ãã¦æ¹è¡ã§åºåãããåºå®ã®æååãã¿ã¼ã³ã®ãªã¹ããæ± ãã¢ã¼ãã§ãã
       egrep 㨠fgrep ã¯ãgrep ã«ãªã³ã¯ãå¼µã£ããã®ã§ãå®ä½ã¯ grep ã§ããgrep ã
       egrep ã®ååã§èµ·åããæã®åä½ã¯ã grep -E ã¨ã»ã¼åãã§ãããã ããå¤ã UNIX ã® egrep
       ã¨ã®äºæã®ãããå®å¨ã«åãã§ã¯ã ãã¾ããã grep ã fgrep ã®ååã§èµ·åããå ´åã¯ã
       grep -F ã¨åãã§ãã

       ãã®ä»ã®ãªãã·ã§ã³ã¯ä»¥ä¸ã®ãã®ãããã¾ãã
       -num   num ã§æå®ããè¡æ°ã ãããã¿ã¼ã³ã«ãããããè¡ã®åå¾ã®è¡ããããã表示ãã¾ãã
       -A num num ã§æå®ããè¡æ°ã ãããã¿ã¼ã³ã«ãããããè¡ã®å¾ã®è¡ã表示ãã¾ãã
       -B num num ã§æå®ããè¡æ°ã ãããã¿ã¼ã³ã«ãããããè¡ã®åã®è¡ã表示ãã¾ãã
       -C     -2 ãæå®ããäºã¨åãã§ããã¿ã¼ã³ã«ãããããè¡ã®åå¾ 2 è¡ã表示ãã¾ãã
       -V     grep ã®ãã¼ã¸ã§ã³çªå·ãæ¨æºã¨ã©ã¼åºåã«è¡¨ç¤ºãã¾ãããã°ã¬ãã¼ã
              ã«ã¯ããã®çªå·ãä»è¨ãã¦ãã ããã
       -b     åè¡ã®åã«ããã¡ã¤ã«ã®åé ãããã¤ãåä½ã®ãªãã»ããã表示ãã¾ãã
       -n   åè¡ã®åã«ãè¡çªå·ã表示ãã¾ãã
       -c     åè¡ã®è¡¨ç¤ºã¯ããããããããè¡æ°ã ãã表示ãã¾ãã -v
              ãªãã·ã§ã³ã¨å±ã«æå®ããå ´åã¯ããããããªãã£ãè¡æ°ã®è¡¨ç¤ºã¨ãªãã¾ãã
       -e pattern
              ãã¿ã¼ã³ãæå®ãã¾ãããã¿ã¼ã³ã®åé ãã -
              ã§å§ã¾ã£ã¦ãããªã©ããªãã·ã§ã³ã®æå®ã¨æ··åãããå¯è½æ§ãããæã«æå¹ã§ãã
              é常ã¯ã -e ãçç¥ãã¦ãã¿ã¼ã³ãè¨è¿°ããäºãã§ãã¾ãã
       -f file
              ãã¿ã¼ã³ã file ããèªã¿è¾¼ã¿ã¾ãã
       -h     è¤æ°ã®ãã¡ã¤ã«ãæå®ããå ´åãããã©ã«ãã§ã¯ããããããè¡ã®å
              ã«ããã¡ã¤ã«åãä»ãã¦è¡¨ç¤ºãè¡ããã¾ããã -h
              ãæå®ããå ´åã¯ããã¡ã¤ã«åãä»ããªãããã«ãã¾ãã
       -i     ãã¿ã¼ã³ãããã«ããã¦ãè±å¤§æåã¨å°æåã®åºå¥ãããªãããã«ãã¾ãã
       -l     é常ã®è¡¨ç¤ºãææ¢ãã代ããã«ããã¿ã¼ã³ã«ããããããã¡ã¤ã«ã®ãã¡ ã¤ã«åã 1
              è¡ãã¤è¡¨ç¤ºãã¾ãã -v
              ã¨å±ã«ä½¿ç¨ããå ´åã¯ããããããªãã£ããã¡ã¤ã«åã®è¡¨ç¤ºã«ãªãã¾ãã
       -L     é常ã®è¡¨ç¤ºãææ¢ãã代ããã«ããã¿ã¼ã³ã«ãããããªãã£ããã¡ã¤ã«åã表示
              ãã¾ãã -lv ã¨åãã§ãã
       -q     é常ã®è¡¨ç¤ºãææ¢ãã¾ãã
       -s     æå®ããããã¡ã¤ã«ãåå¨ããªãå ´åããèªã¿è¾¼ã¿ã§ããªãã£ãæã
              ããã©ã«ãã§ã¯ã¨ã©ã¼ã¡ãã»ã¼ã¸ã表示ãã¾ããããããææ¢ãã¾ãã
       -v     æå®ããããã¿ã¼ã³ã«ãããããªãè¡ã対象ã«ãã¾ãã
       -w     ãã¿ã¼ã³ãããããåèªå¨ä½ã§è¡ãããã«ãã¾ããããã©ã«ãã®å
              ä½ã§ã¯ãæå®ããããã¿ã¼ã³ãè¡ã®ä¸ã®ã©ã®é¨åã«ããããã¦ããã¾ãã¾ãã ãã -w
              ãæå®ããå ´åã¯ãåèªåä½ã¨ãªãã¾ãã åèªã¨ã¯ãã¢ã«ãã¡ããããæ°åããã³ã¢
              ã³ãã¼ã¹ã³ã¢ã¼ãããªãæååã§ããã®åå¾ã¯ã空ç½ãªã©ãåèªãæ§æããªã æå‐
              ããè¡é ãè¡æ«ãªã©ã§åºåããããã®ã§ãã ããã¦ãè¡ã®ä¸‐
              ã®ååèªã«ã¤ãã¦ãåèªãæ§æããæåå¨ã¦ããã¿ã¼ ã³ã¨ããããããã©ãã調ã¹ã¾ãã
       -x     ãã¿ã¼ã³ãããããè¡å¨ä½ã§è¡ãããã«ãã¾ãã

æ£è¦è¡¨ç¾
       grep ã¯ãåºæ¬çãªæ£è¦è¡¨ç¾ã¨ å¤ã UNIX ã® egrep ã«ç¸å½ããæ¡å¼µæ£è¦è¡¨ç¾ã® 2
       種 é¡ã®æ£è¦è¡¨ç¾ãæ±ãäºãã§ãã¾ãããã ããæ¬ grep (GNU ãããã¯ãã® grep)
       ã§ã¯ãã©ã¡ãã®è¡¨ç¾ãæ©è½çã«éãããã¾ãããä»ã®ã¤ã³ããªã¡ã³ãã§ã¯ãåº æ¬æ‐
       £è¦è¡¨ç¾ã¯ãæ¡å¼µæ£è¦è¡¨ç¾ããå¶éãããããã«ãªã£ã¦ãã¾ãããæ¬ grep ã§
       ã¯ã表è¨ä¸ã®éãã ãã§ããããã§ã¯ãæ¡å¼µæ£è¦è¡¨ç¾ã«ã¤ãã¦èª¬æããåºæ¬æ£
       è¦è¡¨ç¾ã¨ã®éãã¯ãã®å¾ã«èª¬æãã¾ãã

       æ£è¦è¡¨ç¾ã®åºæ¬åä½ã¯ãåä¸ã®æåã«ããããã¾ããã¢ã«ãã¡ããããæ°å㪠ã©ã®å¤ãã®æå‐
       ã¯ãããèªèº«ã«ããããã¾ããã¾ããç¹æ®ãªæå³ã®ããæåãã
       ããã¯ã¹ã©ãã·ã¥`\'ãä»ããäºã§ããã®æ¬æ¥ã®æåã«ãããããããã«ãªã ã¾ãã ä¾ãã° 0 㯠0
       ã«ããããã \[ 㯠[ ã«ããããã¾ãã

       [ 㨠] ã§å²ã¾ããæåã®ãªã¹ãã¯ããã®ãªã¹ãã®ä¸ã«å«ã¾ããæåã®ã©ãã
       ã«ã¨ããããããã¨ãã§ãã¾ãããã ãããªã¹ãã®åé ã« ^ ãæ¸ããå ´åã¯ããã®ãªã¹ãã«å«ã¾ã ãªã
       æåã«ããããã¾ãã ä¾ãã°ã [0123456789] ã¯æ°å 1 æåã«ããããã¾ãã [^0123456789]
       ã¯æ°å以å¤ã® 1 æåã«ããããã¾ãã

       2 ã¤ã®æåã®éã« `-' ãä»ãããã¨ã§ãåå¾ 2 ã¤ã®æåã® ASCII ãã£ã©ã¯ã¿ã³ã¼
       ãã®éã«ããæåå¨ä½ãæå®ãããã¨ãã§ãã¾ãã ä¾ãã°ã [0-9] ã¯æ°å 1 æåã«ããããã¾ãã
       [:ã¯ã©ã¹å:]ã§ãç¹å®ã®æåã¯ã©ã¹ãæå®ãããã¨ãã§ãã¾ããã¯ã©ã¹ã«ã¯ã [:alnum:],
       [:alpha:], [:cntrl:], [:digit:], [:graph:], [:lower:], [:print:],
       [:punct:], [:space:], [:upper:], [:xdigit:] ãããã¾ãã ä¾ãã°ã [[:alnum:]]
       㯠[0-9A-Za-z] ã¨åãã§ããã [:alnum:] ã§æå®ããæ¹ã ASCII ã³ã¼ãé ã«ä¾åãã¾ããã

       ãªã¹ãã®ä¸ã§ã¯ãã»ã¨ãã©ã®ç¹æ®æåã¯ãé常ã®æåã¨ãã¦æ±ããã¾ãã ã¾ãã次ã®æå‐
       ãããªã¹ãã®ä¸ã®ä½ç½®ã«ãã£ã¦ã¯ãé常ã®æåã¨ãã¦æ±ããã¾ãã

       ]      ãªã¹ãã®åé ã«ããã°ã] ã«ããã

       ^      ãªã¹ãã®åé 以å¤ã«ããã°ã^ ã«ããã

       -      ãªã¹ãã®æå¾ã«ããã°ã- ã«ããã

       ä¾ãã°ã[][] 㯠] ã [ ã«ããããã¾ãã

       次ã®è¡¨ç¾ã¯ãç¹æ®ãªæå³ãããã¾ãã

       .      ä»»æã® 1 æåã«ããã

       \w     [[:alnum:]] ã¨åãã§ãã¢ã«ãã¡ãããã¨æ°åã«ããã

       \W     [^[:alnum:]] ã¨åãã§ãã¢ã«ãã¡ãããã¨æ°å以å¤ã«ããã

       ^      è¡ã®åé ã«ããã

       $      è¡ã®æå¾ã«ããã

       \<     åèªã®åé ã«ããã

       \>     åèªã®æå¾ã«ããã

       \b     åèªã®ç«¯ã«ããã

       \B     åèªã®ç«¯ ä»¥å¤ ã«ããã

       次ã®è¡¨ç¾ã¯ãä»ã®æ£è¦è¡¨ç¾ã修飾ãã¾ããæ¡å¼µæ£è¦è¡¨ç¾ã§ãã
       ?      ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ãã0 åã 1 åãããããã¾ãããããããªãå ´
              åãä¸è´ã¨ãã¾ãã
       *      ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ãã0 å以ä¸ãããããã¾ãããããããªãå ´åã
              ä¸è´ã¨ãã¾ãã
       +      ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ãããã®æ£è¦è¡¨ç¾ã 1 å以ä¸ãããããã¾ãã
              ãªããå°ãªãã¨ã 1 åã¯ãããããªãã¦ã¯ããã¾ããã
       {n}    ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ããå³å¯ã« n åãããããã¾ãã
       {n,}   ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ãã n å以ä¸ãããããã¾ãã
       {,m}   ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ãã m å以ä¸ã§ãããããã¾ãã
       {n,m}  ä»ã®æ£è¦è¡¨ç¾ã®å¾ã«æå®ãã n åä»¥ä¸ m å以ä¸ã§ãããããã¾ãã
       |      2 ã¤ã®æ£è¦è¡¨ç¾ã®éã«æå®ããã©ã¡ããä¸æ¹ããããããã°ä¸è´ã¨ãã¾ãã
       ()     æ¬å¼§ã§ããã£ãæ£è¦è¡¨ç¾ãã²ã¨ã¾ã¨ã¾ãã§ãããããã¾ããç¹°ãè¿ããªã©ã®
              修飾ã¯ããã®ã¾ã¨ã¾ãã«å¯¾ãã¦ã®æå®ã«ãªãã¾ãã
       \n     æ¬å¼§ã§æ¬ã£ãæ£è¦è¡¨ç¾ã®ã¾ã¨ã¾ãã¯ãåºã¦æ¥ãé çªã«çªå·ãæ¯ããã¦ããã
              ãã®ãã¡ã® n çªç®ã®ãã®ãç¹°ãè¿ãã¾ãã ä¾ãã°ãtaro|hanako 㯠`taro' ã
              `hanako' ã«ããããã¾ãã `su(momo)mo\1mo\1nouti' ã¯
              `sumomomomomomomomonouti' ã«ããããã¾ã

       åºæ¬æ£è¦è¡¨ç¾ã§ã¯ã ?, +, {, |, (, ) ã¯ãæ£è¦è¡¨ç¾ã¨ãã¦ã®ç¹æ®ãªæå³ã¯
       æããããã®æåæ¬æ¥ã®ãã¿ã¼ã³ã«ããããã¾ãã代ããã«ã \?, \+, \{, \|, \(, \)
       ã使ãäºã§ãæ¡å¼µæ£è¦è¡¨ç¾ã¨åãæ©è½ãæã¡ã¾ã¾ãã

       egrep ã¨ãã¦èµ·åããå ´åã { ã¯ãæ£è¦è¡¨ç¾ã¨ãã¦ã®ç¹æ®ãªæå³ã¯æã¡ã¾ããã

æ»ãå¤
       ãã¿ã¼ã³ã«ãããããè¡ãè¦ã¤ãã£ãå ´åã¯ã0 ããè¦ã¤ãããªãã£ãå ´åã¯ã1 ã è¿ãã¾ãããã ãã
       -v ãªãã·ã§ã³ãæå®ãããå ´åã¯ãéã«ãªãã¾ãããã¿ã¼ã³ã®æå®ã®ä»æ¹ãééã£ã¦
       ãããããã¡ã¤ã«ãã¢ã¯ã»ã¹ã§ããªããªã©ã®ã¨ã©ã¼ããããå ´åã¯ã2 ãè¿ãã¾ãã

ãã°
       ãã°ã¬ãã¼ãã¯ã bug-gnu-utils@prep.ai.mit.edu ã¾ã§ Email
       ãã¦ãã ããããã®æã``Subject:'' ã®ã©ãã«ã§ãããã§ããã ``grep'' ã¨ããåèªã
       å¿ããã«å¥ãã¦ãã ããã



GNU Project                    1992 September 10                       GREP(1)