特殊:Badtitle/NS100:Grep
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/grep }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/af | • {{#if: UbuntuHelp:grep|Afrikaans| [[::Grep/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ar | • {{#if: UbuntuHelp:grep|العربية| [[::Grep/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/az | • {{#if: UbuntuHelp:grep|azərbaycanca| [[::Grep/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/bcc | • {{#if: UbuntuHelp:grep|جهلسری بلوچی| [[::Grep/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/bg | • {{#if: UbuntuHelp:grep|български| [[::Grep/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/br | • {{#if: UbuntuHelp:grep|brezhoneg| [[::Grep/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ca | • {{#if: UbuntuHelp:grep|català| [[::Grep/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/cs | • {{#if: UbuntuHelp:grep|čeština| [[::Grep/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/de | • {{#if: UbuntuHelp:grep|Deutsch| [[::Grep/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/el | • {{#if: UbuntuHelp:grep|Ελληνικά| [[::Grep/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/es | • {{#if: UbuntuHelp:grep|español| [[::Grep/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/fa | • {{#if: UbuntuHelp:grep|فارسی| [[::Grep/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/fi | • {{#if: UbuntuHelp:grep|suomi| [[::Grep/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/fr | • {{#if: UbuntuHelp:grep|français| [[::Grep/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/gu | • {{#if: UbuntuHelp:grep|ગુજરાતી| [[::Grep/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/he | • {{#if: UbuntuHelp:grep|עברית| [[::Grep/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/hu | • {{#if: UbuntuHelp:grep|magyar| [[::Grep/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/id | • {{#if: UbuntuHelp:grep|Bahasa Indonesia| [[::Grep/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/it | • {{#if: UbuntuHelp:grep|italiano| [[::Grep/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ja | • {{#if: UbuntuHelp:grep|日本語| [[::Grep/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ko | • {{#if: UbuntuHelp:grep|한국어| [[::Grep/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ksh | • {{#if: UbuntuHelp:grep|Ripoarisch| [[::Grep/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/mr | • {{#if: UbuntuHelp:grep|मराठी| [[::Grep/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ms | • {{#if: UbuntuHelp:grep|Bahasa Melayu| [[::Grep/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/nl | • {{#if: UbuntuHelp:grep|Nederlands| [[::Grep/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/no | • {{#if: UbuntuHelp:grep|norsk| [[::Grep/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/oc | • {{#if: UbuntuHelp:grep|occitan| [[::Grep/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/pl | • {{#if: UbuntuHelp:grep|polski| [[::Grep/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/pt | • {{#if: UbuntuHelp:grep|português| [[::Grep/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ro | • {{#if: UbuntuHelp:grep|română| [[::Grep/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/ru | • {{#if: UbuntuHelp:grep|русский| [[::Grep/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/si | • {{#if: UbuntuHelp:grep|සිංහල| [[::Grep/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/sq | • {{#if: UbuntuHelp:grep|shqip| [[::Grep/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/sr | • {{#if: UbuntuHelp:grep|српски / srpski| [[::Grep/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/sv | • {{#if: UbuntuHelp:grep|svenska| [[::Grep/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/th | • {{#if: UbuntuHelp:grep|ไทย| [[::Grep/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/tr | • {{#if: UbuntuHelp:grep|Türkçe| [[::Grep/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/vi | • {{#if: UbuntuHelp:grep|Tiếng Việt| [[::Grep/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/yue | • {{#if: UbuntuHelp:grep|粵語| [[::Grep/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/zh | • {{#if: UbuntuHelp:grep|中文| [[::Grep/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/zh-hans | • {{#if: UbuntuHelp:grep|中文(简体)| [[::Grep/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:grep | UbuntuHelp:grep | {{#if: | :}}Grep}}/zh-hant | • {{#if: UbuntuHelp:grep|中文(繁體)| [[::Grep/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:grep|:Grep|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Grep/zh | | {{#ifexist: Grep/zh | | {{#ifeq: {{#titleparts:Grep|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Grep|1|-1|}} | zh | | }}
What Is grep?
Grep is a command line tool that allows you to find a string in a file or stream. It can be used with Regular expression to be more flexible at finding strings.
How To Use grep
In the simplest case, grep can simply be invoked like this :
% grep 'STRING' filename
This is OK but it does not show the true power of grep. First this only looks at one file. A cool example of using grep with multiple file would be to find all files in a directory that contains the name of a person. This can be easily accomplished using a grep in the following way :
% grep 'Nicolas Kassis' *
Notice the use of single quotes; the quotes are not essential, but in this example they are required because the name contains a space. Double quotes could also have been used in this example. Now lets use some regular expressions...
Grep Regular Expression
grep can search for complicated patterns to find what you need. Here is a list of some of the special characters used to create a regular expression:
Grep Regular Expression | ||
^ | Denotes the beginning of a line | |
$ | Denotes the end of a line | |
. | Matches any one characters | |
* | Matches 0 or more of the previous characters | |
.* | Matches any number or type of characters | |
[] | Matches on character for the one listed in the the Square brackets | |
[^] | Does not match any characters listed | |
\ | Denotes the beginning and end (respectively) of a word |
So an example of a regular expression search would be
% grep "\<[A-Za-z].*" file
This will search for any word which begins with a letter upper or lower case. For more details check:
- BasicCommands
- http://www.gnu.org/software/emacs/manual/html_node/emacs/Grep-Searching.html
- http://en.wikipedia.org/wiki/Grep
- man grep and info grep on your computer