From ac78de2516fcb0c749ad226c093b1e8228efa830 Mon Sep 17 00:00:00 2001 From: Sean Oliver Date: Mon, 22 Oct 2018 19:49:23 -0400 Subject: [PATCH 1/5] added reference page for grep --- _commands/tools/grep.md | 89 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 _commands/tools/grep.md diff --git a/_commands/tools/grep.md b/_commands/tools/grep.md new file mode 100644 index 000000000..a9865901c --- /dev/null +++ b/_commands/tools/grep.md @@ -0,0 +1,89 @@ +--- +--- + +grep +--- +`grep` is a linux command that processes text and prints any lines that match a specified pattern. `grep` stands for **G**lobal **R**egular **E**xpression **P**rint. + +```bash +$grep [OPTIONS] PATTERN [FILE...] +``` + + +##Examples +Imagine a file called test.txt: +``` +Linux is fun +C4CS is cool +CS is awesome +``` +Running grep with the pattern "C4CS" will return the line all lines containg that pattern. +```bash +$grep C4CS test.txt +C4CS is cool +``` + +## Regular Expressions +The real power of grep comes from its ability to use regular expressions as a pattern. For the folowing examples consider a dictionary called dict.txt. +###Bracket Expressions +A bracket expression is a list of characters enclosed by [ and ]. A bracket expression will match any single character in the list. +```bash +$grep c[aou]t dict.txt +cat +cot +cut +``` +bracket expressions can also be used with a hypen to match a range. [a-e] is equivlent to [abcde]. And [0-9] is equivlent to [0123456789]. +###Negating a Bracket Expression +A carat (^) at the begining of a bracketed expression will match characters not in the list. +```bash +$grep c[^u]t dict.txt +cat +cot +``` +###Anchoring +The ^ symbol is used to match at the begining of the string. The $ symbol is used to match at the end of the string. +```bash +$grep t dict.txt +# returns all words containing an 't' +$grep ^t dict.txt +# returns all words begining with 't' +$grep t$ dict.txt +# returns all words ending in 't' +###Wildcard +The . symbol is used as a wildcard. It can match any single character. +```bash +$grep .oat dict.txt +boat +coat +goat +moat +``` +###Repetition +The ? symbol means the preceding item may be matched zero or one times. ab?c matches both "ac" and "abc". +The * symbol means the preceding item may be matched zero or more times. ab*c mathces "ac", "abc", "abbc", and so on. +The + symbol means the preceding item may be matched one or more times. ab+c matches "abc", "abbc", "abbbc", and so on. +{n} means the preceding item is matched exactly n times. a{5} matches "aaaaa". +{n,} means the preceding item is matched n or more times. a{3,} matches "aaa", "aaaa", and so on. +{,n} means the preceding item is matched at most n times. a{,3} matches "","a","aa","aaa". +{n,m} means the preceding item is matched at least n times and at most m times. a{1,3} matches "a","aa","aaa". + +##grep Options + +###-i, --ignore-case +Uses case insesitive matching for the PATTERN. +###-v, --invert-match +Prints lines that do not match the PATTERN. +###-c, --count +Does not print matching lines, instead prints the number of matching lines. +Can be used in combination with -v as -cv to print the number of non-matching lines. +###-q, --quiet, --silent +Do not print anything. Exit 0 if any match is found, even if there is an error. +###-H, --with-filename +Print the filename for eaach match. This option is default when provided with more than one file. +###-h, --no-filename +Suppress output of file names. This is default when provided with only one file to search +###-n, --line-number +Prefix each line of output with the 1-based line number within its file. +###-R, -r, --recursive +Read all files under a directory From 3d2aebbe511b1ecb1122c88b91fca4f25d25d8dd Mon Sep 17 00:00:00 2001 From: Sean Oliver Date: Mon, 22 Oct 2018 19:53:07 -0400 Subject: [PATCH 2/5] fixed header formatting --- _commands/tools/grep.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/_commands/tools/grep.md b/_commands/tools/grep.md index a9865901c..02c856a93 100644 --- a/_commands/tools/grep.md +++ b/_commands/tools/grep.md @@ -25,7 +25,7 @@ C4CS is cool ## Regular Expressions The real power of grep comes from its ability to use regular expressions as a pattern. For the folowing examples consider a dictionary called dict.txt. -###Bracket Expressions +### Bracket Expressions A bracket expression is a list of characters enclosed by [ and ]. A bracket expression will match any single character in the list. ```bash $grep c[aou]t dict.txt @@ -34,14 +34,14 @@ cot cut ``` bracket expressions can also be used with a hypen to match a range. [a-e] is equivlent to [abcde]. And [0-9] is equivlent to [0123456789]. -###Negating a Bracket Expression +### Negating a Bracket Expression A carat (^) at the begining of a bracketed expression will match characters not in the list. ```bash $grep c[^u]t dict.txt cat cot ``` -###Anchoring +### Anchoring The ^ symbol is used to match at the begining of the string. The $ symbol is used to match at the end of the string. ```bash $grep t dict.txt @@ -50,7 +50,7 @@ $grep ^t dict.txt # returns all words begining with 't' $grep t$ dict.txt # returns all words ending in 't' -###Wildcard +### Wildcard The . symbol is used as a wildcard. It can match any single character. ```bash $grep .oat dict.txt @@ -59,7 +59,7 @@ coat goat moat ``` -###Repetition +### Repetition The ? symbol means the preceding item may be matched zero or one times. ab?c matches both "ac" and "abc". The * symbol means the preceding item may be matched zero or more times. ab*c mathces "ac", "abc", "abbc", and so on. The + symbol means the preceding item may be matched one or more times. ab+c matches "abc", "abbc", "abbbc", and so on. @@ -68,22 +68,22 @@ The + symbol means the preceding item may be matched one or more times. ab+c mat {,n} means the preceding item is matched at most n times. a{,3} matches "","a","aa","aaa". {n,m} means the preceding item is matched at least n times and at most m times. a{1,3} matches "a","aa","aaa". -##grep Options +## grep Options -###-i, --ignore-case +### -i, --ignore-case Uses case insesitive matching for the PATTERN. -###-v, --invert-match +### -v, --invert-match Prints lines that do not match the PATTERN. -###-c, --count +### -c, --count Does not print matching lines, instead prints the number of matching lines. Can be used in combination with -v as -cv to print the number of non-matching lines. -###-q, --quiet, --silent +### -q, --quiet, --silent Do not print anything. Exit 0 if any match is found, even if there is an error. -###-H, --with-filename +### -H, --with-filename Print the filename for eaach match. This option is default when provided with more than one file. -###-h, --no-filename +### -h, --no-filename Suppress output of file names. This is default when provided with only one file to search -###-n, --line-number +### -n, --line-number Prefix each line of output with the 1-based line number within its file. -###-R, -r, --recursive +### -R, -r, --recursive Read all files under a directory From e1ef4f0b1e42b1b78c201dbcfd3214bb1b093813 Mon Sep 17 00:00:00 2001 From: Sean Oliver Date: Mon, 22 Oct 2018 20:02:38 -0400 Subject: [PATCH 3/5] moved grep.md to appropiate folder --- _commands/scripting/grep.md | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 _commands/scripting/grep.md diff --git a/_commands/scripting/grep.md b/_commands/scripting/grep.md new file mode 100644 index 000000000..02c856a93 --- /dev/null +++ b/_commands/scripting/grep.md @@ -0,0 +1,89 @@ +--- +--- + +grep +--- +`grep` is a linux command that processes text and prints any lines that match a specified pattern. `grep` stands for **G**lobal **R**egular **E**xpression **P**rint. + +```bash +$grep [OPTIONS] PATTERN [FILE...] +``` + + +##Examples +Imagine a file called test.txt: +``` +Linux is fun +C4CS is cool +CS is awesome +``` +Running grep with the pattern "C4CS" will return the line all lines containg that pattern. +```bash +$grep C4CS test.txt +C4CS is cool +``` + +## Regular Expressions +The real power of grep comes from its ability to use regular expressions as a pattern. For the folowing examples consider a dictionary called dict.txt. +### Bracket Expressions +A bracket expression is a list of characters enclosed by [ and ]. A bracket expression will match any single character in the list. +```bash +$grep c[aou]t dict.txt +cat +cot +cut +``` +bracket expressions can also be used with a hypen to match a range. [a-e] is equivlent to [abcde]. And [0-9] is equivlent to [0123456789]. +### Negating a Bracket Expression +A carat (^) at the begining of a bracketed expression will match characters not in the list. +```bash +$grep c[^u]t dict.txt +cat +cot +``` +### Anchoring +The ^ symbol is used to match at the begining of the string. The $ symbol is used to match at the end of the string. +```bash +$grep t dict.txt +# returns all words containing an 't' +$grep ^t dict.txt +# returns all words begining with 't' +$grep t$ dict.txt +# returns all words ending in 't' +### Wildcard +The . symbol is used as a wildcard. It can match any single character. +```bash +$grep .oat dict.txt +boat +coat +goat +moat +``` +### Repetition +The ? symbol means the preceding item may be matched zero or one times. ab?c matches both "ac" and "abc". +The * symbol means the preceding item may be matched zero or more times. ab*c mathces "ac", "abc", "abbc", and so on. +The + symbol means the preceding item may be matched one or more times. ab+c matches "abc", "abbc", "abbbc", and so on. +{n} means the preceding item is matched exactly n times. a{5} matches "aaaaa". +{n,} means the preceding item is matched n or more times. a{3,} matches "aaa", "aaaa", and so on. +{,n} means the preceding item is matched at most n times. a{,3} matches "","a","aa","aaa". +{n,m} means the preceding item is matched at least n times and at most m times. a{1,3} matches "a","aa","aaa". + +## grep Options + +### -i, --ignore-case +Uses case insesitive matching for the PATTERN. +### -v, --invert-match +Prints lines that do not match the PATTERN. +### -c, --count +Does not print matching lines, instead prints the number of matching lines. +Can be used in combination with -v as -cv to print the number of non-matching lines. +### -q, --quiet, --silent +Do not print anything. Exit 0 if any match is found, even if there is an error. +### -H, --with-filename +Print the filename for eaach match. This option is default when provided with more than one file. +### -h, --no-filename +Suppress output of file names. This is default when provided with only one file to search +### -n, --line-number +Prefix each line of output with the 1-based line number within its file. +### -R, -r, --recursive +Read all files under a directory From 0acec29b5f76a54c010b75b687727c68f2a77f69 Mon Sep 17 00:00:00 2001 From: Sean Oliver <36770636+oliversno@users.noreply.github.com> Date: Tue, 23 Oct 2018 11:58:52 -0400 Subject: [PATCH 4/5] Fixed typo in grep.md --- _commands/scripting/grep.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_commands/scripting/grep.md b/_commands/scripting/grep.md index 02c856a93..abcb89544 100644 --- a/_commands/scripting/grep.md +++ b/_commands/scripting/grep.md @@ -10,7 +10,7 @@ $grep [OPTIONS] PATTERN [FILE...] ``` -##Examples +## Examples Imagine a file called test.txt: ``` Linux is fun From 3231ecf693e0259d8eac98c61e948930300b7cc4 Mon Sep 17 00:00:00 2001 From: Sean Oliver <36770636+oliversno@users.noreply.github.com> Date: Tue, 23 Oct 2018 12:02:06 -0400 Subject: [PATCH 5/5] Removed grep.md from _tools --- _commands/tools/grep.md | 89 ----------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 _commands/tools/grep.md diff --git a/_commands/tools/grep.md b/_commands/tools/grep.md deleted file mode 100644 index 02c856a93..000000000 --- a/_commands/tools/grep.md +++ /dev/null @@ -1,89 +0,0 @@ ---- ---- - -grep ---- -`grep` is a linux command that processes text and prints any lines that match a specified pattern. `grep` stands for **G**lobal **R**egular **E**xpression **P**rint. - -```bash -$grep [OPTIONS] PATTERN [FILE...] -``` - - -##Examples -Imagine a file called test.txt: -``` -Linux is fun -C4CS is cool -CS is awesome -``` -Running grep with the pattern "C4CS" will return the line all lines containg that pattern. -```bash -$grep C4CS test.txt -C4CS is cool -``` - -## Regular Expressions -The real power of grep comes from its ability to use regular expressions as a pattern. For the folowing examples consider a dictionary called dict.txt. -### Bracket Expressions -A bracket expression is a list of characters enclosed by [ and ]. A bracket expression will match any single character in the list. -```bash -$grep c[aou]t dict.txt -cat -cot -cut -``` -bracket expressions can also be used with a hypen to match a range. [a-e] is equivlent to [abcde]. And [0-9] is equivlent to [0123456789]. -### Negating a Bracket Expression -A carat (^) at the begining of a bracketed expression will match characters not in the list. -```bash -$grep c[^u]t dict.txt -cat -cot -``` -### Anchoring -The ^ symbol is used to match at the begining of the string. The $ symbol is used to match at the end of the string. -```bash -$grep t dict.txt -# returns all words containing an 't' -$grep ^t dict.txt -# returns all words begining with 't' -$grep t$ dict.txt -# returns all words ending in 't' -### Wildcard -The . symbol is used as a wildcard. It can match any single character. -```bash -$grep .oat dict.txt -boat -coat -goat -moat -``` -### Repetition -The ? symbol means the preceding item may be matched zero or one times. ab?c matches both "ac" and "abc". -The * symbol means the preceding item may be matched zero or more times. ab*c mathces "ac", "abc", "abbc", and so on. -The + symbol means the preceding item may be matched one or more times. ab+c matches "abc", "abbc", "abbbc", and so on. -{n} means the preceding item is matched exactly n times. a{5} matches "aaaaa". -{n,} means the preceding item is matched n or more times. a{3,} matches "aaa", "aaaa", and so on. -{,n} means the preceding item is matched at most n times. a{,3} matches "","a","aa","aaa". -{n,m} means the preceding item is matched at least n times and at most m times. a{1,3} matches "a","aa","aaa". - -## grep Options - -### -i, --ignore-case -Uses case insesitive matching for the PATTERN. -### -v, --invert-match -Prints lines that do not match the PATTERN. -### -c, --count -Does not print matching lines, instead prints the number of matching lines. -Can be used in combination with -v as -cv to print the number of non-matching lines. -### -q, --quiet, --silent -Do not print anything. Exit 0 if any match is found, even if there is an error. -### -H, --with-filename -Print the filename for eaach match. This option is default when provided with more than one file. -### -h, --no-filename -Suppress output of file names. This is default when provided with only one file to search -### -n, --line-number -Prefix each line of output with the 1-based line number within its file. -### -R, -r, --recursive -Read all files under a directory