Skip to content

Commit 7c6ffe0

Browse files
updates for version 1.1
1 parent f668249 commit 7c6ffe0

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

gnu_awk.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Resources mentioned in Acknowledgements section are available under original lic
6666

6767
## Book version
6868

69-
1.0
69+
1.1
7070
See [Version_changes.md](https://github.com/learnbyexample/learn_gnuawk/blob/master/Version_changes.md) to track changes across book versions.
7171

7272
# Installation and Documentation
@@ -691,11 +691,11 @@ part time
691691

692692
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 `\\`.
693693

694-
Unlike `grep` and `sed`, the line anchors have to be always escaped to match them literally. They do not lose their special meaning when not used in their customary positions.
694+
Unlike `grep` and `sed`, the line anchors have to be always escaped to match them literally as there is no BRE mode in `awk`. They do not lose their special meaning when not used in their customary positions.
695695

696696
```bash
697697
$ # awk '/b^2/' will not work even though ^ isn't being used as anchor
698-
$ # however, b^2 will work for both grep and sed
698+
$ # b^2 will work for both grep and sed if you use BRE syntax
699699
$ echo 'a^2 + b^2 - C*3' | awk '/b\^2/'
700700
a^2 + b^2 - C*3
701701

@@ -3064,13 +3064,12 @@ $ echo "$s" | awk 'match($0, /0*[1-9][0-9]{2,}/, m){print m[0]}'
30643064
154
30653065
```
30663066
3067-
Both the above examples can also be easily solved using `FPAT` or `patsplit`. `match` has an advantage when it comes to getting portions matched only within capture groups. The first element of array will still have the entire match. Second element will contain portion matched by first group, third element will contain portion matched by second group and so on.
3067+
Both the above examples can also be easily solved using `FPAT` or `patsplit`. `match` has an advantage when it comes to getting portions matched only within capture groups. The first element of array will still have the entire match. Second element will contain portion matched by first group, third element will contain portion matched by second group and so on. See also [stackoverflow: arithmetic replacement in a text file](https://stackoverflow.com/questions/62241101/arithmetic-replacement-in-a-text-file).
30683068
30693069
```bash
30703070
$ # entire matched portion
30713071
$ echo 'foo=42, baz=314' | awk 'match($0, /baz=([0-9]+)/, m){print m[0]}'
30723072
baz=314
3073-
30743073
$ # matched portion of first capture group
30753074
$ echo 'foo=42, baz=314' | awk 'match($0, /baz=([0-9]+)/, m){print m[1]}'
30763075
314

0 commit comments

Comments
 (0)