grep
| grep | |
|---|---|
Example of grep command | |
| Original author(s) | Ken Thompson[1][2] |
| Developer(s) | AT&T Bell Laboratories |
| Initial release | November 1973[1] |
| Operating system | Unix, Unix-like, Plan 9, Inferno, OS-9, MSX-DOS, IBM i |
| Platform | Cross-platform |
| Type | Command |
grep은 정규 표현식과 일치하는 줄에 대한 일반 텍스트 데이터 집합을 검색하기 위한 명령줄 유틸리티입니다. 그 이름은 ed 명령 g/re/p (globally search for a regular expression and print matching lines)에서 왔으며, 같은 효과를 발휘합니다.[3][4] grep은 원래 유닉스 운영 시스템에 대해 개발되었지만, 나중에 모든 유닉스-계열 시스템 및 OS-9와 같은 일부 다른 시스템에서 사용할 수 있습니다.[5]
History
그것이 이름-지정되기 전에, grep은 특정 패턴에 대한 파일을 검색하기 위해 Ken Thompson에 의해 작성된 개인 유틸리티였습니다. Doug McIlroy는 그것의 존재를 모르고 Thompson에게 그러한 프로그램을 작성하도록 요청했습니다. Thompson은 하룻밤 사이에 그러한 유틸리티에 대해 생각할 것이라고 응답했으며, 그는 실제로 약 1시간 동안 버그를 수정하고 향상된 기능을 만들었습니다. 다음날 그는 그 프로그램을 McIlroy에게 제시했고, McIlroy는 그것이 정확히 그가 원하는 것이라고 말했습니다. Thompson의 설명은 grep이 하룻밤에 작성되었다는 믿음을 설명할 수 있습니다.[6]
Thompson은 Lee E. McMahon이 개별 논문의 저자를 결정하기 위해 Federalist Papers의 텍스트를 분석하는 데 도움이 되도록 PDP-11 어셈블리 언어로 첫 번째 버전을 작성했습니다.[7] ed 텍스트 편집기 (역시 Thompson에 의해 작성)는 정규 표현식 지원이 있었지만 그렇게 많은 양의 텍스트에는 사용할 수 없었으므로, Thompson은 해당 코드를 독립 실행형 도구로 발췌했습니다.[1] 그는 ed에서 g/re/p 명령이 지정된 패턴과 일치하는 모든 행을 인쇄할 것이기 때문에 이름을 선택했습니다.[8][9] grep은 버전 4 유닉스에 처음 포함되었습니다. McIlroy는 "일반적으로 그 프로토타입 소프트웨어 도구로 인용되었다"고 말하면서 grep이 유닉스에서 Thompson의 도구 철학을 "돌이킬 수 없을 정도로 뿌리내린" 것으로 인정했습니다.[10]
Sample usage
다음 예제는 서로 다른 주어진 인수를 갖는 grep 명령의 출력을 보여줍니다:
$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
$ grep -n root /etc/passwd
1:root:x:0:0:root:/root:/bin/bash
12:operator:x:11:0:operator:/root:/sbin/nologin
$ grep -c false /etc/passwd
7
Implementations
다양한 grep 구현은 많은 운영 시스템과 소프트웨어 개발 환경에서 사용할 수 있습니다.[11] 초기 변형은 버전 7 유닉스에 도입된 egrep과 fgrep을 포함했었습니다.[10] "egrep" 변형은 Ken Thompson의 원래 정규식 구현 이후에 Alfred Aho에 의해 추가된 확장된 정규 표현식 구문을 지원합니다.[12] "fgrep" 변형은 Aho–Corasick 문자열 일치 알고리듬을 사용하여 고정된 문자열 목록의 임의의 것에 대해 검색합니다.[13] 이들 변형의 이진 파일은 대부분의 최신 시스템에서 지속되며, 보통 grep에 연결됩니다; 어쨌든, 이들 이진 파일를 사용하는 것은 grep의 -E와 -F 명령줄 스위치를 대신 사용하기 위해 더 이상 사용되지 않습니다.[14]
다른 명령은 전형적으로 정규 표현식 일치에 의존하는 검색 도구임을 나타내기 위해 단어 "grep"을 포함합다. pgrep 유틸리티는, 예를 들어, 이름이 주어진 정규 표현식과 일치하는 과정을 표시합니다.[15]
Perl 프로그래밍 언어에서, grep은 목록에서 특정 속성을 만족하는 요소를 찾는 내장 함수의 이름입니다.[16] 이 고차 함수는 전형적으로 filter 또는 다른 언어에서 where로 이름-지어졌습니다.
pcregrep 명령은 Perl 정규 표현식 구문을 사용하는 grep의 구현입니다.[17] 비슷한 기능성은 -P 플래그를 갖는 GNU 버전의 grep에서 호출될 수 있습니다.[18]
grep의 이식 (예를 들어, Cygwin와 GnuWin32 내에서)은 역시 윈도우에서 실행됩니다. 일부 윈도우 버전은 유사한 qgrep 또는 findstr 명령이 있습니다.[19]
grep 명령은 역시 ASCII의 MSX-DOS 버전 2에 대해 MSX-DOS2 도구의 일부입니다.[20]
grep, egrep, 및 fgrep 명령은 역시 IBM i 운영 시스템으로 이식되었습니다.[21]
소프트웨어 Adobe InDesign은 find/change 대화 상자[22] "GREP" 탭에서 GREP (CS3 버전(2007) 이후[23]) 기능을 가지고, paragraph styles[24] "GREP 스타일"에서 InDesign CS4[25]와 함께 도입되었습니다.
agrep
agrep (근사적인 grep)은 텍스트가 오직 근사적으로 검색 패턴에 맞을 때 일치합니다.[26]
이 다음 호출은 파일 myfile에서 netmasks를 찾지만, 역시 두 개 이하의 대체가 주어지면 그것에서 파생될 수 있는 임의의 다른 단어를 찾습니다:
agrep -2 netmasks myfile
이 예제는 가장 가까운 것, 즉 가장 적은 수의 대체 항목이 먼저 나열된 일치 항목 목록을 생성합니다. 명령 플래그 B는 best를 의미합니다:
agrep -B netmasks myfile
Usage as a verb
2003년 12월에, Oxford English Dictionary Online은 "grep"에 대해 초안 항목을 명사와 동사로 추가했습니다.
공통적인 동사 용법은 "죽은 나무를 grep할 수 없습니다"라는 문구입니다–하드 카피 (예를 들어, 죽은 나무로부터 만들어진 것, 종이)보다 grep과 같은 도구를 사용하여 디지털 미디어를 통해 더 쉽게 검색할 수 있다는 의미입니다.[27] google과 비교해 보십시오.
See also
- Boyer–Moore string search algorithm
- agrep, an approximate string-matching command
- find (Windows), a DOS and Windows command that performs text searches, similar to a simple
grep - find (Unix), a Unix command that finds files by attribute, very different from
grep - List of Unix commands
- vgrep, or "visual
grep" - The Platinum Searcher, a faster search
References
- ^ a b c Kernighan, Brian (1984). The Unix Programming Environment. Prentice Hall. pp. 102. ISBN 0-13-937681-X.
- ^ “grep was a private command of mine for quite a while before i made it public.” -Ken Thompson Archived 2015-05-26 at the Wayback Machine, By Benjamin Rualthanzauva, Published on Feb 5, 2014, Medium
- ^ Hauben et al. 1997, Ch. 9
- ^ Raymond, Eric. "grep". Jargon File. Archived from the original on 2006-06-17. Retrieved 2006-06-29.
- ^ Paul S. Dayan (1992). The OS-9 Guru - 1 : The Facts. Galactic Industrial Limited. ISBN 0-9519228-0-7.
- ^ VCF East 2019 -- Brian Kernighan interviews Ken Thompson (video). YouTube. 6 May 2019. (35 mins)
- ^ Computerphile, Where GREP Came From, interview with Brian Kernighan
- ^ "ed regexes". perl.plover.com. Archived from the original on 20 October 2017. Retrieved 24 April 2018.
- ^ "How Grep Got its Name". robots.thoughtbot.com. Archived from the original on 9 August 2017. Retrieved 24 April 2018.
- ^ a b McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139. Archived (PDF) from the original on 2017-11-11.
- ^ Abou-Assaleh, Tony; Wei Ai (March 2004). Survey of Global Regular Expression Print (GREP) Tools (Technical report). Dalhousie University.
- ^ Hume, Andrew (1988). "A Tale of Two Greps". Software—Practice & Experience. 18 (11): 1063. doi:10.1002/spe.4380181105. S2CID 6395770.
- ^ Meurant, Gerard (12 Sep 1990). Algorithms and Complexity. Elsevier Science. p. 278. ISBN 9780080933917. Archived from the original on 4 March 2016. Retrieved 12 December 2015.
- ^ "grep". www.pubs.opengroup.org. The Open Group. Archived from the original on 28 November 2015. Retrieved 12 December 2015.
- ^ "pgrep(1)". www.linux.die.net. Archived from the original on 22 December 2015. Retrieved 12 December 2015.
- ^ "grep". www.perldoc.perl.org. Archived from the original on 7 December 2015. Retrieved 12 December 2015.
- ^ "pcregrep man page". www.pcre.org. University of Cambridge. Archived from the original on 23 December 2015. Retrieved 12 December 2015.
- ^ "grep(1)". www.linux.die.net. Archived from the original on 10 December 2015. Retrieved 12 December 2015.
- ^ Spalding, George (2000). Windows 2000 administration. Network professional's library. Osborne/McGraw-Hill. pp. 634. ISBN 978-0-07-882582-8. Retrieved 2010-12-10.
QGREP.EXE[:] A similar tool to grep in UNIX, this tool can be used to search for a text string
- ^ MSX-DOS2 Tools User's Manual by ASCII Corporation
- ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). Retrieved 2020-09-05.
- ^ "InDesign Help: find/change". Archived from the original on 2016-08-28. Retrieved 2016-08-12.
- ^ "Review: Adobe InDesign CS3 - CreativePro.com". creativepro.com. 20 April 2007. Archived from the original on 5 January 2018. Retrieved 24 April 2018.
- ^ "InDesign Help: GREP styles". Archived from the original on 2016-08-28. Retrieved 2016-08-12.
- ^ "Archived copy". Archived from the original on 2017-09-24. Retrieved 2018-01-05.
{{cite web}}: CS1 maint: archived copy as title (link) - ^ S. Lee Henry (June 1998). "Proper Searching". Sun Expert. pp. 35–26.
- ^ Jargon File, article "Documentation"
- Notes
- Alain Magloire (August 2000). Grep: Searching for a Pattern. Iuniverse Inc. ISBN 0-595-10039-2.
- Hume, Andrew Grep wars: The strategic search initiative. In Peter Collinson, editor, Proceedings of the EUUG Spring 88 Conference, pages 237–245, Buntingford, UK, 1988. European UNIX User Group.
- Michael Hauben; et al. (April 1997). Netizens: On the History and Impact of Usenet and the Internet (Perspectives). Wiley-IEEE Computer Society Press. ISBN 978-0-8186-7706-9.
External links
- GNU Grep official website
- GNU Grep manual
- – Plan 9 Programmer's Manual, Volume 1
- – Inferno General commands Manual
- "why GNU grep is fast" - implementation details from GNU grep's author.
- Network grep - A packet analyzer used to match patterns at the network layer
- Command Grep – 25 practical examples