오늘은 대한입니다.
sun's longitude:299 44 13.02 
· 자유게시판 · 묻고답하기 · 알파문서 · RPMS list
· 사용자문서 · 팁/FAQ모음 · 리눅스Links · 자료실
· 서버정보 · 운영자 · Books/FAQ · FreeBSD
/board/read.php:소스보기  
알파문서
자주 잊어먹거나, 메모해 둘 필요성이 있는 팁이나 문서, 기타 등등
[*** 쓰기 금지단어 패턴 ***]
글 본문 중간에 업로드할 이미지를 추가하는 방법 : @@이미지이름@@
ex) @@foo.gif@@
4 번 글: [GNU sed] 메타 문자와 그룹화
글쓴이: 산이 [홈페이지] 글쓴날: 2003년 01월 09일 00:13:01 목(새벽) 조회: 4503
다른 정규표현식과 상당히 헷갈리는 sed
(자주 잊어먹음)

예)
$ echo 'abc(def)g' | sed 's/^\([^(]\+\)(\([^)]\+\))/\1_\2_/g'
abc_def_g


's/^\([^(]\+\)(\([^)]\+\))/\1_\2_/g'
    ^^^^^^^^^^ ^^^^^^^^^^
       abc    (   def    )
       \1         \2

메타문자를 구룹화할 경우 탈출(\) 문자추가
(다른 정규표현식과 다른점)


+  -> \+   -> 문자 집합([class])에 대한 하나 이상
() -> \(\) -> 그룹화에 사용 -> \1, \2, \3, ... \9
{} -> \{\} -> 반복범위 지정
|  -> \|   -> or 연산
-----------------------

^   -> 메타문자, 라인의 시작
$   -> 메타문자, 라인의 끝
[]  -> 메타문자, 어떤 문자들의 집합, 메타문자로 인식
\   -> 메타문자, 메타문자를 탈출
*   -> 메타문자, 문자 집합에 대한 0 이상 /*** 주의 ***/
.   -> 메타문자, 어떤 문자든지 매칭
()  -> '('와 ')' 문자, 메타문자로 인식하지 않음
?   -> '?' 문자, 메타문자로 인식하지 않음



\`  - matches the beginning of the pattern space (same as "^")
\'  - matches the end of the pattern space (same as "$")
\?  - 0 or 1 occurrences of previous character: same as \{0,1\}
\+  - 1 or more occurrences of previous character: same as \{1,\}
\|  - matches the string on either side, e.g., foo\|bar
\b  - boundary between word and nonword chars (reversible)
\B  - boundary between 2 word or between 2 nonword chars
\n  - embedded newline (usable after N, G, or similar commands)
\w  - any word character: [A-Za-z0-9_]
\W  - any nonword char: [^A-Za-z0-9_]
\<  - boundary between nonword and word character
\>  - boundary between word and nonword character


[[:alnum:]]  -> [A-Za-z0-9]     Alphanumeric characters
[[:alpha:]]  -> [A-Za-z]        Alphabetic characters
[[:blank:]]  -> [ \x09]         Space or tab characters only
[[:cntrl:]]  -> [\x00-\x19\x7F] Control characters
[[:digit:]]  -> [0-9]           Numeric characters
[[:graph:]]  -> [!-~]           Printable and visible characters
[[:lower:]]  -> [a-z]           Lower-case alphabetic characters
[[:print:]]  -> [ -~]           Printable (non-Control) characters
[[:punct:]]  -> [!-/:-@[-`{-~]  Punctuation characters
[[:space:]]  -> [ \t\v\f]       All whitespace chars
[[:upper:]]  -> [A-Z]           Upper-case alphabetic characters
[[:xdigit:]] -> [0-9a-fA-F]     Hexadecimal digit characters


URL
http://www.ptug.org/sed/sedfaq.htm

EOF

 
이전글 : [PHP] strtr, preg_replace, str_replace
다음글 : [grep /egrep]  
 from 61.254.75.40
JS(Redhands)Board 0.4 +@

|글쓰기| |답장쓰기| |수정|
|이전글| |다음글| |목록보기|
인쇄용 

apache lighttpd linuxchannel.net 
Copyright 1997-2026. linuxchannel.net. All rights reserved.

Page loading: 0.01(server) + (network) + (browser) seconds