Skip to content

Commit ca6cd91

Browse files
updates for version 1.6
#1
1 parent b25c2e8 commit ca6cd91

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

gnu_grep.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Resources mentioned in Acknowledgements section are available under original lic
6464

6565
## Book version
6666

67-
1.5
67+
1.6
6868

6969
See [Version_changes.md](https://github.com/learnbyexample/learn_gnugrep_ripgrep/blob/master/Version_changes.md) to track changes across book versions.
7070

@@ -854,17 +854,17 @@ part time
854854
855855
## Escaping metacharacters
856856
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.
858858
859859
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.
860860
861861
```bash
862-
$ # line anchors aren't special away from customary positions
862+
$ # line anchors aren't special away from customary positions with BRE
863863
$ echo 'a^2 + b^2 - C*3' | grep 'b^2'
864864
a^2 + b^2 - C*3
865865
$ echo '$a = $b + $c' | grep '$b'
866866
$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
868868
$ echo '$a = $b + $c' | grep -o '\$' | wc -l
869869
3
870870
$ # or use -F where possible
@@ -1859,7 +1859,7 @@ By default, recursive search options `-r` and `-R` will include hidden files as
18591859
18601860
>![info](images/info.svg) `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.
18611861
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).
18631863
18641864
```bash
18651865
$ # without customizing
@@ -3187,7 +3187,7 @@ $ rm f[12]
31873187
31883188
Using PCRE usually will be faster if search pattern has backreferences.
31893189
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)
31913191
31923192
>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.
31933193
@@ -3243,7 +3243,7 @@ With this, chapters on `GNU grep` are done. Would highly suggest to maintain you
32433243
32443244
# ripgrep
32453245
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.
32473247
32483248
**Project links**
32493249

0 commit comments

Comments
 (0)