You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: gnu_grep.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ Resources mentioned in Acknowledgements section are available under original lic
64
64
65
65
## Book version
66
66
67
-
1.5
67
+
1.6
68
68
69
69
See [Version_changes.md](https://github.com/learnbyexample/learn_gnugrep_ripgrep/blob/master/Version_changes.md) to track changes across book versions.
70
70
@@ -854,17 +854,17 @@ part time
854
854
855
855
## Escaping metacharacters
856
856
857
-
You have seen a few metacharacters and escape sequences that help to compose a regular expression. To match the metacharacters literally, i.e. to remove their special meaning, prefix those characters with a `\` character. To indicate a literal `\` character, use `\\`. Some of the metacharacters, like the line anchors, lose their special meaning when not used in their customary positions.
857
+
You have seen a few metacharacters and escape sequences that help to compose a regular expression. To match the metacharacters literally, i.e. to remove their special meaning, prefix those characters with a `\` character. To indicate a literal `\` character, use `\\`. Some of the metacharacters, like the line anchors, lose their special meaning when not used in their customary positions with BRE syntax.
858
858
859
859
If there are many metacharacters to be escaped, try to work out if the command can be simplified by using `-F` (paired with regular expression like options such as `-e`, `-f`, `-i`, `-w`, `-x`, etc) or by switching between ERE and BRE. Another option is to use PCRE (covered later), which has special constructs to mark whole or portion of pattern to be matched literally — especially useful when using shell variables.
860
860
861
861
```bash
862
-
$ # line anchors aren't special away from customary positions
862
+
$ # line anchors aren't special away from customary positions with BRE
863
863
$ echo 'a^2 + b^2 - C*3' | grep 'b^2'
864
864
a^2 + b^2 - C*3
865
865
$ echo '$a = $b + $c' | grep '$b'
866
866
$a = $b + $c
867
-
$ # escape line anchors to match literally at customary positions
867
+
$ # escape line anchors to match literally at customary positions, also for ERE
868
868
$ echo '$a = $b + $c' | grep -o '\$' | wc -l
869
869
3
870
870
$ # or use -F where possible
@@ -1859,7 +1859,7 @@ By default, recursive search options `-r` and `-R` will include hidden files as
1859
1859
1860
1860
> `PATTERN` here refers to `glob` or `wildcard` patterns used by shell to expand filenames (not the same as regular expressions). The `PATTERN` applies only to basename of file or directory, not the pathname. Which implies that you cannot use `/`in the globs specified in conjunction with recursive options.
1861
1861
1862
-
Each of these options can be used multiple times to precisely specify the search paths. To know more about `wildcards` see [wooledge: glob](https://mywiki.wooledge.org/glob) and my own [tutorial on glob](https://github.com/learnbyexample/Linux_command_line/blob/master/Shell.md#wildcards).
1862
+
Each of these options can be used multiple times to precisely specify the search paths. These can be used without recursive options too. If you mix `--include` and `--exclude` options, their order of declaration matters. To know more about `wildcards` see [wooledge: glob](https://mywiki.wooledge.org/glob).
1863
1863
1864
1864
```bash
1865
1865
$ # without customizing
@@ -3187,7 +3187,7 @@ $ rm f[12]
3187
3187
3188
3188
Using PCRE usually will be faster if search pattern has backreferences.
3189
3189
3190
-
As mentioned earlier, from `man grep` under **Known Bugs** section (wrt BRE/ERE)
3190
+
As mentioned earlier, from `man grep` under **Known Bugs** section (applies to BRE/ERE)
3191
3191
3192
3192
>Large repetition counts in the {n,m} construct may cause grep to use lots of memory. In addition, certain other obscure regular expressions require exponential time and space, and may cause grep to run out of memory. Back-references are very slow, and may require exponential time.
3193
3193
@@ -3243,7 +3243,7 @@ With this, chapters on `GNU grep` are done. Would highly suggest to maintain you
3243
3243
3244
3244
# ripgrep
3245
3245
3246
-
`ripgrep` is definitely becoming a popular alternative (if not the most popular) to `grep` command. Editors like [Visual Studio Code](https://code.visualstudio.com/updates/v1_11) and [Atom](https://github.com/atom/fuzzy-finder/pull/369) are using `ripgrep` to power their search offerings. The major selling point is its default behavior for recursive search and speed. The project doesn't aim to be compatible with POSIX and behavior varies wrt`GNU grep` in terms of features, option names, output style, regular expressions, etc.
3246
+
`ripgrep` is definitely becoming a popular alternative (if not the most popular) to `grep` command. Editors like [Visual Studio Code](https://code.visualstudio.com/updates/v1_11) and [Atom](https://github.com/atom/fuzzy-finder/pull/369) are using `ripgrep` to power their search offerings. The major selling point is its default behavior for recursive search and speed. The project doesn't aim to be compatible with POSIX and behavior varies with respect to`GNU grep` in terms of features, option names, output style, regular expressions, etc.
0 commit comments