diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-02-16 00:29:35 +0100 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-02-16 00:29:35 +0100 |
commit | 4485708c972815bbb6df7f5a228683aa855d553d (patch) | |
tree | dd730bff8d461499111d577255acda8b2abd49f7 /src/tools/awk.md | |
parent | 723da2def58185891bf6541dc254d09da8932bff (diff) | |
download | notes-4485708c972815bbb6df7f5a228683aa855d553d.tar.gz notes-4485708c972815bbb6df7f5a228683aa855d553d.zip |
awk: split on multiple tokens
Diffstat (limited to 'src/tools/awk.md')
-rw-r--r-- | src/tools/awk.md | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/tools/awk.md b/src/tools/awk.md index a0c2470..d6f6c9c 100644 --- a/src/tools/awk.md +++ b/src/tools/awk.md @@ -144,6 +144,12 @@ echo 'a b c d e f' | awk '{ print $NF $(NF-1) }' ``` Access last fields with arithmetic on the `NF` number of fields variable. +### Split on multiple tokens +```bash +echo 'a,b;c:d' | awk -F'[,;:]' '{ printf "1=%s | 4=%s\n", $1, $4 }' +``` +Use regex as field separator. + ### Capture in variables ```bash # /proc/<pid>/status |