grep 옵션 사용 방법
(리눅스 grep usage help, regexp 정규식 표현)

리눅스에서 사용하는 grep 명령어의 옵션에 대해서 알아봅니다.
[dev]$ grep --helpgrep --help
Usage: grep [OPTION]... PATTERN [FILE]...
Search for PATTERN in each FILE or standard input.
PATTERN is, by default, a basic regular expression (BRE).
Example: grep -i 'hello world' menu.h main.c
Regexp selection and interpretation:
  -E, --extended-regexp     PATTERN is an extended regular expression (ERE)
  -F, --fixed-strings       PATTERN is a set of newline-separated fixed strings
  -G, --basic-regexp        PATTERN is a basic regular expression (BRE)
  -P, --perl-regexp         PATTERN is a Perl regular expression
  -e, --regexp=PATTERN      use PATTERN for matching
  -f, --file=FILE           obtain PATTERN from FILE
  -i, --ignore-case         ignore case distinctions
  -w, --word-regexp         force PATTERN to match only whole words
  -x, --line-regexp         force PATTERN to match only whole lines
  -z, --null-data           a data line ends in 0 byte, not newline
Miscellaneous:
  -s, --no-messages         suppress error messages
  -v, --invert-match        select non-matching lines
  -V, --version             display version information and exit
      --help                display this help text and exit
Output control:
  -m, --max-count=NUM       stop after NUM matches
  -b, --byte-offset         print the byte offset with output lines
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line
  -H, --with-filename       print the file name for each match
  -h, --no-filename         suppress the file name prefix on output
      --label=LABEL         use LABEL as the standard input file name prefix
  -o, --only-matching       show only the part of a line matching PATTERN
  -q, --quiet, --silent     suppress all normal output
      --binary-files=TYPE   assume that binary files are TYPE;
                            TYPE is 'binary', 'text', or 'without-match'
  -a, --text                equivalent to --binary-files=text
  -I                        equivalent to --binary-files=without-match
  -d, --directories=ACTION  how to handle directories;
                            ACTION is 'read', 'recurse', or 'skip'
  -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                            ACTION is 'read' or 'skip'
  -r, --recursive           like --directories=recurse
  -R, --dereference-recursive
                            likewise, but follow all symlinks
      --include=FILE_PATTERN
                            search only files that match FILE_PATTERN
      --exclude=FILE_PATTERN
                            skip files and directories matching FILE_PATTERN
      --exclude-from=FILE   skip files matching any file pattern from FILE
      --exclude-dir=PATTERN directories that match PATTERN will be skipped.
  -L, --files-without-match print only names of FILEs containing no match
  -l, --files-with-matches  print only names of FILEs containing matches
  -c, --count               print only a count of matching lines per FILE
  -T, --initial-tab         make tabs line up (if needed)
  -Z, --null                print 0 byte after FILE name
Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
  -NUM                      same as --context=NUM
      --group-separator=SEP use SEP as a group separator
      --no-group-separator  use empty string as a group separator
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is 'always', 'never', or 'auto'
  -U, --binary              do not strip CR characters at EOL (MSDOS/Windows)
  -u, --unix-byte-offsets   report offsets as if CRs were not there
                            (MSDOS/Windows)
'egrep' means 'grep -E'.  'fgrep' means 'grep -F'.
Direct invocation as either 'egrep' or 'fgrep' is deprecated.
When FILE is -, read standard input.  With no FILE, read . if a command-line
-r is given, - otherwise.  If fewer than two FILEs are given, assume -h.
Exit status is 0 if any line is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.
Report bugs to: bug-grep@gnu.org
GNU Grep home page: <http://www.gnu.org/software/grep/>
General help using GNU software: <http://www.gnu.org/gethelp/>
아래와 같은 testHost 파일이 있다고 할때
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
iamfreemangrep 명령어 AND 조건 ( 파이프, pipe | 사용)
grep 명령어를 사용하면서 여러개의 단어를 AND 조건으로 사용하기 위해서 파이프( pipe, | ) 로 연결해주면 됩니다.
[/home/iamfreeman] grep '192.168.1' testHost | grep 'tistory.com'
192.168.1.230 iamfreeman.tistory.com
[/home/iamfreeman]
-E 옵션 사용 방법 (grep 명령어 OR 조건)
OR 조건으로 검색하고자할때 다음과 같이 -E 명령어 옵션( -E, --extended-regexp     PATTERN is an extended regular expression (ERE) )으로 사용 할 수 있습니다.
홀따옴표( ' )안에서 괄호와 파이프( pipe, | )를 통해서 OR 조건을 추가해주시면 됩니다.
'egrep' means 'grep -E'. 
아래와 같이 egrep 명령은 'grep -E' 명령을 사용한것과 동일합니다.
[/home1/iamfreeman] grep -E '192.168.1.(230|231)' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
[/home1/iamfreeman] 
[/home1/iamfreeman] egrep '192.168.1.(230|231)' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
[/home1/iamfreeman]
-i 옵션 사용 방법 (ignore case distinctions)
-i, --ignore-case         ignore case distinctionsgrep에서의 default는 알파벳의 대소문자를 구분해서 조회합니다.
-i 옵션을 사용하면
찾고자하는 문자열에 대해서 알파벳의 대소문자 구분없이 조회하고자 할때 사용합니다.
아래의 명령어 사용 방법과 출력 값을 토대로 -i 옵션 사용의 차이점을 확인해보세요.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] 
[/home1/iamfreeman] grep 'iamfreeman' testHost   
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -i 'iamfreeman' testHost              
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
IAMFREEMAN
-w 옵션 사용 방법 (force PATTERN to match only whole words)
 -w, --word-regexp         force PATTERN to match only whole words일치하는 부분이 단어의 일부가 아닌 whole words인 경우만을 찾아줍니다.
사용 방법과 결과는 다음과 같습니다.
아래의 결과값을 토대로 비교해보세요.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
[/home1/iamfreeman] grep 'iamfreeman' testHost        
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
[/home1/iamfreeman] grep -w 'iamfreeman' testHost
192.168.1.230 iamfreeman.tistory.com
[/home1/iamfreeman]
-x 옵션 사용 방법 (force PATTERN to match only whole lines)
-x, --line-regexp         force PATTERN to match only whole linesgrep 명령어의 -x 옵션을 사용해볼까요?
아래의 명령어 사용 방법을 보시고, 어떤 차이점이 있는지를 직접 확인해보세요.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
iamfreeman
yourfreeman
[/home1/iamfreeman] grep -x '192.168.1' testHost                                   
[/home1/iamfreeman] grep -x '192.168.1.230' testHost
[/home1/iamfreeman] grep -x '192.168.1.230 iamfreeman.tistory.com' testHost
192.168.1.230 iamfreeman.tistory.com각 명령어 실행의 차이점을 눈치 채셨나요?
-x 옵션의 설명에도 있듯이,
한줄 전체의 내용과 일치하는 것을 골라내 줍니다.
-v 옵션 사용 방법 (select non-matching lines)
-v, --invert-match        select non-matching lines-v 옵션을 사용하여 문자열이 포함되지 않은 줄들을 결과값으로 출력해줍니다.
사용방법은 다음과 같습니다.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -v 'iamfreeman' testHost
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
yourfreeman
IAMFREEMAN
[/home1/iamfreeman]
starts with 문자열 찾기 ( ^ 사용, startswith)
찾고자하는 문자열 중에서 해당 줄의 시작되는 문자열을 찾고자하는 경우에 아래와 같이 사용하세요.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
iamfreeman
yourfreeman
[/home1/iamfreeman] grep '^friend.com' testHost         
[/home1/iamfreeman] grep '^10.1.112' testHost          
[/home1/iamfreeman] grep '^10.10.1.112' testHost      
10.10.1.112 friends.com
[/home1/iamfreeman]각 명령어 실행의 차이점을 찾으셨나요?
^ 옵션을 사용할때는 startswith. 즉, 해당 줄에서 시작되는 문자열을 찾아줍니다.
정규식 표현을 통해서 찾고자하는 시작문자열의 알파벳을 지정해줄수도 있습니다.
아래의 예와 같이 대소문자의 구분도 가능합니다.
[/home1/iamfreeman] cat testHost                 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] grep '^[a-j]' testHost
[/home1/iamfreeman] 
[/home1/iamfreeman] grep '^[a-z]' testHost          
wowiamfreeman
yourfreeman
[/home1/iamfreeman] 
[/home1/iamfreeman] grep '^[A-Z]' testHost          
IAMFREEMAN
[/home1/iamfreeman]
ends with 문자열 찾기 ( $ 사용, endswith)
찾고자하는 문자열 중에서 해당 줄의 끝나는 문자열을 찾고자하는 경우에 아래와 같이 사용하세요.
[/home1/iamfreeman] cat testHost            
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
iamfreeman
yourfreeman
[/home1/iamfreeman] grep 'freeman$' testHost 
iamfreeman
yourfreeman
[/home1/iamfreeman] grep 'iamfreeman$' testHost
iamfreeman
[/home1/iamfreeman]각 명령어의 실행 방법을 비교해보세요.
$ 를 사용하면 한 줄의 마지막에 해당하는 문자열로된 행만을 찾을 수 있습니다.
정규식 표현을 통해서 찾고자하는 끝 문자열의 알파벳을 지정해줄수도 있습니다.
아래의 예와 같이 대소문자의 구분도 가능합니다.
[/home1/iamfreeman] cat testHost                                      
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] 
[/home1/iamfreeman] grep '[a-m]$' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep '[A-Z]$' testHost          
IAMFREEMAN
한줄의 공백 찾기 (^$ 사용)
자~~ 그럼 이전에 사용해본 두개의 명령어를 응용해볼까요?
한줄 전체가 공백인 줄을 찾아보죠.
사용하는 명령어는 ^$ 를 아래와 같이 사용하면 됩니다.
[/home1/iamfreeman] grep '^$' testHost          
[/home1/iamfreeman]
-b 옵션 사용 방법. ( -b, --byte-offset print the byte offset with output lines )
결과 값의 byte offset 값을 출력해줍니다.
아래의 결과 값을 보실까요?
첫번째 행 결과 값의 byte offset인 0
두번째 행 결과 값인 byte offset인 37...
[/home1/iamfreeman] grep -b '192.168.1' testHost
0:192.168.1.230 iamfreeman.tistory.com
37:192.168.1.231 danaga.com
62:192.168.1.232 dagarae.com
[/home1/iamfreeman]
-m 옵션 사용 방법. ( -m, --max-count=NUM stop after NUM matches )
파일에서 찾고자하는 문자열이 여러개일 경우에
결과값으로 최대 몇개까지만 보고 싶을때 사용하는 옵션입니다.
사용 방법은 다음과 같습니다.
[/home1/iamfreeman] cat testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
iamfreeman
yourfreeman
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -m 1 '192.168.1' testHost
192.168.1.230 iamfreeman.tistory.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -m 2 '192.168.1' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
[/home1/iamfreeman] grep -m 3 '192.168.1' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
[/home1/iamfreeman]
-n 옵션 사용 방법. 줄 넘버 출력하기 (line number)
파일에서 찾고자하는 문자열이 여러개이거나,
수십만 라인의 파일일 경우에 내가 원하는 문자열의 위치를 알기 위해서
해당 문자열의 line number를 알고자 하는 경우에 사용할 수 있습니다.
  -n, --line-number         print line number with output lines
      --line-buffered       flush output on every line사용 방법은 다음과 같으며, -E 옵션과 같이 사용해 보았습니다.
-n 옵션을 사용하였을 경우 맨 앞의 값이 line number 값 입니다.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
iamfreeman
yourfreeman
[/home1/iamfreeman] grep -E '192.168.1.(230|231)' testHost   
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
[/home1/iamfreeman]
[/home1/iamfreeman] grep -n -E '192.168.1.(230|231)' testHost                          
1:192.168.1.230 iamfreeman.tistory.com
2:192.168.1.231 danaga.com
[/home1/iamfreeman]
-H 옵션 혹은 -h 옵션 사용 방법 (파일명 출력 혹은 파일명 출력하지 않기 옵션)
여러개의 파일에 대해서 조회를 할때
각 파일별로의 결과를 확인하고 싶으실때가 있죠?
그럴때 사용하시면 됩니다.
더불어서... 파일명이 출력이 안되었으면 하는 경우도 있겠죠?
  -H, --with-filename       print the file name for each match
  -h, --no-filename         suppress the file name prefix on output
      --label=LABEL         use LABEL as the standard input file name prefix[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
iamfreeman
yourfreeman
[/home1/iamfreeman] 
[/home1/iamfreeman] cat danagaHost 
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
192.168.1.233 greptest.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -n -E '192.168.1.(230|231)' testHost
1:192.168.1.230 iamfreeman.tistory.com
2:192.168.1.231 danaga.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -n -H -E '192.168.1.(230|231)' testHost
testHost:1:192.168.1.230 iamfreeman.tistory.com
testHost:2:192.168.1.231 danaga.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -n -E '192.168.1.(230|231)' *Host                           
danagaHost:1:192.168.1.231 danaga.com
testHost:1:192.168.1.230 iamfreeman.tistory.com
testHost:2:192.168.1.231 danaga.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -n -H -E '192.168.1.(230|231)' *Host
danagaHost:1:192.168.1.231 danaga.com
testHost:1:192.168.1.230 iamfreeman.tistory.com
testHost:2:192.168.1.231 danaga.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -n -h -E '192.168.1.(230|231)' *Host
1:192.168.1.231 danaga.com
1:192.168.1.230 iamfreeman.tistory.com
2:192.168.1.231 danaga.com
[/home1/iamfreeman]위의 사용예를 보시면 아시겠지만
-E 옵션을 사용해서 여러개의 파일에 대해서 grep 명령을 사용하면 파일명을 앞에 출력해줍니다.
여러개 파일에 대한 결과값 출력시에 -H 옵션이 default 처럼 사용된다는 것이죠.
여기서 -h 옵션 ( -h, --no-filename )의 사용 필요성이 대두됩니다.
난... 여러개 파일에 대해서 조회할때 파일명이 앞에 안나왔으면 좋겠어. 하시는 분들이 사용하시면 되겠죠.
[/home1/iamfreeman] grep -n -h -E '192.168.1.(230|231)' *Host
1:192.168.1.231 danaga.com
1:192.168.1.230 iamfreeman.tistory.com
2:192.168.1.231 danaga.com
-c 옵션 사용 방법. 파일마다의 일치하는 행의 개수 만을 출력
-c, --count               print only a count of matching lines per FILE아래의 사용예를 토대로 어떠한 결과값을 보여주는지 확인해볼까요?
-c 옵션을 사용하면
문자열이 일치하는 파일마다의 행수를 출력해줍니다.
결과값은 파일명이 먼저 출력되고, 다음으로 문자열이 일치하는 행수를 출력해 줍니다.
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] 
[/home1/iamfreeman] cat danagaHost 
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
192.168.1.233 greptest.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep '[a-m]$' *Host
danagaHost:192.168.1.231 danaga.com
danagaHost:192.168.1.232 dagarae.com
danagaHost:192.168.1.233 greptest.com
testHost:192.168.1.230 iamfreeman.tistory.com
testHost:192.168.1.231 danaga.com
testHost:192.168.1.232 dagarae.com
testHost:10.10.1.112 friends.com
[/home1/iamfreeman] 
[/home1/iamfreeman] grep -c '[a-m]$' *Host
danagaHost:3
testHost:4
[/home1/iamfreeman]
--color 옵션 사용 방법
위의 결과 값 중에서 자신이 찾고자하는 문자열을 색깔로 구분지어 주고 싶다면,
보는 입장에서 더 확실하게 눈에 띄겠죠?
그럴 경우 --color 옵션을 사용해보세요.
      --color[=WHEN],
      --colour[=WHEN]       use markers to highlight the matching strings;
                            WHEN is 'always', 'never', or 'auto'
grep 정규식 표현 사용 방법
Character Classes
- [[:alnum:]]
 Alphanumeric characters: ‘[:alpha:]’ and ‘[:digit:]’; in the ‘C’ locale and ASCII character encoding, this is the same as ‘[0-9A-Za-z]’.
- [[:alpha:]]
 Alphabetic characters: ‘[:lower:]’ and ‘[:upper:]’; in the ‘C’ locale and ASCII character encoding, this is the same as ‘[A-Za-z]’.
- [[:blank:]]
 Blank characters: space and tab.
- [[:cntrl:]]
 Control characters. In ASCII, these characters have octal codes 000 through 037, and 177 (DEL). In other character sets, these are the equivalent characters, if any.
- [[:digit:]]
 Digits: 0 1 2 3 4 5 6 7 8 9.
- [[:graph:]]
 Graphical characters: ‘[:alnum:]’ and ‘[:punct:]’.
- [[:lower:]]
 Lower-case letters; in the ‘C’ locale and ASCII character encoding, this is a b c d e f g h i j k l m n o p q r s t u v w x y z.
- [[:print:]]
 Printable characters: ‘[:alnum:]’, ‘[:punct:]’, and space.
- [[:punct:]]
 Punctuation characters; in the ‘C’ locale and ASCII character encoding, this is ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~.
- [[:space:]]
 Space characters: in the ‘C’ locale, this is tab, newline, vertical tab, form feed, carriage return, and space. See Usage, for more discussion of matching newlines.
- [[:upper:]]
 Upper-case letters: in the ‘C’ locale and ASCII character encoding, this is A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.
- [[:xdigit:]]
 Hexadecimal digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f.
Character Classes의 사용예들을 살펴볼까요?
[/home1/iamfreeman] cat testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman]
[/home1/iamfreeman] 
[/home1/iamfreeman] egrep '[[:digit:]]{2}' testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] egrep '[[:digit:]]{3}' testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] egrep '[[:digit:]]{4}' testHost 
[/home1/iamfreeman] egrep '[[:digit:]]{,3}' testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:digit:]]{1,3}' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] egrep '[[:digit:]]{1,2}' testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] egrep '[[:digit:]]{1,2}' testHost
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] 
[/home1/iamfreeman] 
[/home1/iamfreeman] egrep '[[:blank:]]{1,2}' testHost     
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
[/home1/iamfreeman] egrep '[[:blank:]]{2}' testHost   
[/home1/iamfreeman] egrep '[[:alnum:]]{2}' testHost       
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:alnum:]]{10}' testHost 
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:alnum:]]{20}' testHost 
[/home1/iamfreeman] 
[/home1/iamfreeman] egrep '[[:alpha:]]{6}' testHost       
192.168.1.230 iamfreeman.tistory.com
192.168.1.231 danaga.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:alpha:]]{7}' testHost 
192.168.1.230 iamfreeman.tistory.com
192.168.1.232 dagarae.com
10.10.1.112 friends.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:alpha:]]{9}' testHost  
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:alpha:]]{10}' testHost 
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
yourfreeman
IAMFREEMAN
[/home1/iamfreeman] egrep '[[:alpha:]]{13}' testHost  
wowiamfreeman
[/home1/iamfreeman] egrep '[[:lower:]]{10}' testHost      
192.168.1.230 iamfreeman.tistory.com
wowiamfreeman
yourfreeman
[/home1/iamfreeman] egrep '[[:upper:]]{10}' testHost     
IAMFREEMAN
[/home1/iamfreeman]
- ‘]’
 ends the bracket expression if it’s not the first list item. So, if you want to make the ‘]’ character a list item, you must put it first.
- ‘[.’
 represents the open collating symbol.
- ‘.]’
 represents the close collating symbol.
- ‘[=’
 represents the open equivalence class.
- ‘=]’
 represents the close equivalence class.
- ‘[:’
 represents the open character class symbol, and should be followed by a valid character class name.
- ‘:]’
 represents the close character class symbol.
- ‘-’
 represents the range if it’s not first or last in a list or the ending point of a range.
- ‘^’
 represents the characters not in the list. If you want to make the ‘^’ character a list item, place it anywhere but first.
'Development > 리눅스' 카테고리의 다른 글
| 리눅스 OS, Apache, Tomcat, Java, Mysql, Postgres, PPAS, Oracle 버전 확인 방법 (0) | 2022.01.24 | 
|---|---|
| 리눅스 OS 버전, bit 확인하기 (OS & version, cpu, bit check) (0) | 2022.01.24 | 
| netstat의 state별 설명 (0) | 2019.06.16 | 
| Linux에서의 인포믹스 설치 문서... (2) | 2019.06.16 | 
| http ▶▶▶ https 강제 전환 설정하기 (0) | 2019.03.27 | 
 
										
									 
										
									
댓글