From 4485708c972815bbb6df7f5a228683aa855d553d Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Fri, 16 Feb 2024 00:29:35 +0100 Subject: awk: split on multiple tokens --- src/tools/awk.md | 6 ++++++ 1 file changed, 6 insertions(+) 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//status -- cgit v1.2.3