Created
December 30, 2011 02:24
-
-
Save wgzhao/1537350 to your computer and use it in GitHub Desktop.
shell regular expression sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash$ cat textfile | |
This is line 1, of which there is only one instance. | |
This is the only instance of line 2. | |
This is line 3, another line. | |
This is line 4. | |
bash$ grep 'the' textfile | |
This is line 1, of which there is only one instance. | |
This is the only instance of line 2. | |
This is line 3, another line. | |
bash$ grep '\' textfile | |
This is the only instance of line 2. | |
The only way to be certain that a particular RE works is to test it. | |
TEST FILE: tstfile # No match. | |
# No match. | |
Run grep "1133*" on this file. # Match. | |
# No match. | |
# No match. | |
This line contains the number 113. # Match. | |
This line contains the number 13. # No match. | |
This line contains the number 133. # No match. | |
This line contains the number 1133. # Match. | |
This line contains the number 113312. # Match. | |
This line contains the number 1112. # No match. | |
This line contains the number 113312312. # Match. | |
This line contains no numbers at all. # No match. | |
bash$ grep "1133*" tstfile | |
Run grep "1133*" on this file. # Match. | |
This line contains the number 113. # Match. | |
This line contains the number 1133. # Match. | |
This line contains the number 113312. # Match. | |
This line contains the number 113312312. # Match. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment