From a4c0535e6dbd30f1af75a0a8d6fa23d3ab94e6d2 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Wed, 14 May 2025 12:16:58 +0300 Subject: [PATCH 1/8] Create awk.md --- pages/linux/awk.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pages/linux/awk.md diff --git a/pages/linux/awk.md b/pages/linux/awk.md new file mode 100644 index 00000000000000..18819d636dd645 --- /dev/null +++ b/pages/linux/awk.md @@ -0,0 +1,36 @@ +# awk + +> A versatile programming language for working on files. +> More information: . + +- Print the fifth column (a.k.a. field) in a space-separated file: + +`awk '{print $5}' {{path/to/file}}` + +- Print the second column of the lines containing "foo" in a space-separated file: + +`awk '/{{foo}}/ {print $2}' {{path/to/file}}` + +- Print the last column of each line in a file, using a comma (instead of space) as a field separator: + +`awk {{[-F|--field-separator]}} ',' '{print $NF}' {{path/to/file}}` + +- Sum the values in the first column of a file and print the total: + +`awk '{s+=$1} END {print s}' {{path/to/file}}` + +- Print every third line starting from the first line: + +`awk 'NR%3==1' {{path/to/file}}` + +- Print different values based on conditions: + +`awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` + +- Print all the lines which the 10th column value is between a min and a max: + +`awk '($10 >= {{min_value}} && $10 <= {{max_value}})'` + +- Print table of users with UID >=1000 with header and formatted output, using colon as separator (`%-20s` mean: 20 left-align string characters, `%6s` means: 6 right-align string characters): + +`awk 'BEGIN {FS=":";printf "%-20s %6s %25s\n", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s\n", $1, $4, $7}' /etc/passwd` From 83c9d27b822052c326c1e25d3b1664e38993ecf2 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Wed, 14 May 2025 16:00:58 +0300 Subject: [PATCH 2/8] Create gawk.md --- pages/common/gawk.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 pages/common/gawk.md diff --git a/pages/common/gawk.md b/pages/common/gawk.md new file mode 100644 index 00000000000000..0af11dea948803 --- /dev/null +++ b/pages/common/gawk.md @@ -0,0 +1,37 @@ +# gawk + +> GNU version of awk, a versatile programming language for working on files. +> See also: `awk`. +> More information: . + +- Print the fifth column (a.k.a. field) in a space-separated file: + +`awk '{print $5}' {{path/to/file}}` + +- Print the second column of the lines containing "foo" in a space-separated file: + +`awk '/{{foo}}/ {print $2}' {{path/to/file}}` + +- Print the last column of each line in a file, using a comma (instead of space) as a field separator: + +`awk {{[-F|--field-separator]}} ',' '{print $NF}' {{path/to/file}}` + +- Sum the values in the first column of a file and print the total: + +`awk '{s+=$1} END {print s}' {{path/to/file}}` + +- Print every third line starting from the first line: + +`awk 'NR%3==1' {{path/to/file}}` + +- Print different values based on conditions: + +`awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` + +- Print all the lines which the 10th column value is between a min and a max: + +`awk '($10 >= {{min_value}} && $10 <= {{max_value}})'` + +- Print table of users with UID >=1000 with header and formatted output, using colon as separator (`%-20s` mean: 20 left-align string characters, `%6s` means: 6 right-align string characters): + +`awk 'BEGIN {FS=":";printf "%-20s %6s %25s\n", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s\n", $1, $4, $7}' /etc/passwd` From 77178e0e4004713f38e22391c996b2f857454c65 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Wed, 14 May 2025 16:01:53 +0300 Subject: [PATCH 3/8] Delete pages/linux/awk.md --- pages/linux/awk.md | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 pages/linux/awk.md diff --git a/pages/linux/awk.md b/pages/linux/awk.md deleted file mode 100644 index 18819d636dd645..00000000000000 --- a/pages/linux/awk.md +++ /dev/null @@ -1,36 +0,0 @@ -# awk - -> A versatile programming language for working on files. -> More information: . - -- Print the fifth column (a.k.a. field) in a space-separated file: - -`awk '{print $5}' {{path/to/file}}` - -- Print the second column of the lines containing "foo" in a space-separated file: - -`awk '/{{foo}}/ {print $2}' {{path/to/file}}` - -- Print the last column of each line in a file, using a comma (instead of space) as a field separator: - -`awk {{[-F|--field-separator]}} ',' '{print $NF}' {{path/to/file}}` - -- Sum the values in the first column of a file and print the total: - -`awk '{s+=$1} END {print s}' {{path/to/file}}` - -- Print every third line starting from the first line: - -`awk 'NR%3==1' {{path/to/file}}` - -- Print different values based on conditions: - -`awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` - -- Print all the lines which the 10th column value is between a min and a max: - -`awk '($10 >= {{min_value}} && $10 <= {{max_value}})'` - -- Print table of users with UID >=1000 with header and formatted output, using colon as separator (`%-20s` mean: 20 left-align string characters, `%6s` means: 6 right-align string characters): - -`awk 'BEGIN {FS=":";printf "%-20s %6s %25s\n", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s\n", $1, $4, $7}' /etc/passwd` From eed24b71a41e98fbb9b8ca23878becd9daaa2c96 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Wed, 14 May 2025 16:02:28 +0300 Subject: [PATCH 4/8] Update awk.md --- pages/common/awk.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/common/awk.md b/pages/common/awk.md index fc1346bd2db902..9c261b30ac6b77 100644 --- a/pages/common/awk.md +++ b/pages/common/awk.md @@ -1,6 +1,7 @@ # awk > A versatile programming language for working on files. +> See also: `gawk`. > More information: . - Print the fifth column (a.k.a. field) in a space-separated file: From f03ee840a18bb0b82212a28f3d69a91c500b1a83 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Wed, 14 May 2025 16:03:15 +0300 Subject: [PATCH 5/8] Update awk.md --- pages/common/awk.md | 1 + 1 file changed, 1 insertion(+) diff --git a/pages/common/awk.md b/pages/common/awk.md index 9c261b30ac6b77..5b2b6357a461f8 100644 --- a/pages/common/awk.md +++ b/pages/common/awk.md @@ -1,6 +1,7 @@ # awk > A versatile programming language for working on files. +> Different versions often make this a symlink of their binary. > See also: `gawk`. > More information: . From 684967611c8e39be0e5a7d2f92b9b10f14d17f7f Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Thu, 15 May 2025 16:55:50 +0300 Subject: [PATCH 6/8] Update pages/common/awk.md Co-authored-by: Fazle Arefin --- pages/common/awk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/common/awk.md b/pages/common/awk.md index 5b2b6357a461f8..1aabdb8743a5af 100644 --- a/pages/common/awk.md +++ b/pages/common/awk.md @@ -1,7 +1,7 @@ # awk > A versatile programming language for working on files. -> Different versions often make this a symlink of their binary. +> Note: Different implementations of AWK often make this a symlink of their binary. > See also: `gawk`. > More information: . From 56733a6165c990fe1b4d914da27df44515eba42f Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Sat, 17 May 2025 11:27:28 +0300 Subject: [PATCH 7/8] Update pages/common/gawk.md Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> --- pages/common/gawk.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/common/gawk.md b/pages/common/gawk.md index 0af11dea948803..1efa7a8dd56d82 100644 --- a/pages/common/gawk.md +++ b/pages/common/gawk.md @@ -6,7 +6,7 @@ - Print the fifth column (a.k.a. field) in a space-separated file: -`awk '{print $5}' {{path/to/file}}` +`gawk '{print $5}' {{path/to/file}}` - Print the second column of the lines containing "foo" in a space-separated file: From 52b896501a736d39c624190facb7e65d1114edc6 Mon Sep 17 00:00:00 2001 From: Managor <42655600+Managor@users.noreply.github.com> Date: Sat, 17 May 2025 11:28:44 +0300 Subject: [PATCH 8/8] Update gawk.md --- pages/common/gawk.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pages/common/gawk.md b/pages/common/gawk.md index 1efa7a8dd56d82..aad1e467aa20c3 100644 --- a/pages/common/gawk.md +++ b/pages/common/gawk.md @@ -10,28 +10,28 @@ - Print the second column of the lines containing "foo" in a space-separated file: -`awk '/{{foo}}/ {print $2}' {{path/to/file}}` +`gawk '/{{foo}}/ {print $2}' {{path/to/file}}` - Print the last column of each line in a file, using a comma (instead of space) as a field separator: -`awk {{[-F|--field-separator]}} ',' '{print $NF}' {{path/to/file}}` +`gawk {{[-F|--field-separator]}} ',' '{print $NF}' {{path/to/file}}` - Sum the values in the first column of a file and print the total: -`awk '{s+=$1} END {print s}' {{path/to/file}}` +`gawk '{s+=$1} END {print s}' {{path/to/file}}` - Print every third line starting from the first line: -`awk 'NR%3==1' {{path/to/file}}` +`gawk 'NR%3==1' {{path/to/file}}` - Print different values based on conditions: -`awk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` +`gawk '{if ($1 == "foo") print "Exact match foo"; else if ($1 ~ "bar") print "Partial match bar"; else print "Baz"}' {{path/to/file}}` - Print all the lines which the 10th column value is between a min and a max: -`awk '($10 >= {{min_value}} && $10 <= {{max_value}})'` +`gawk '($10 >= {{min_value}} && $10 <= {{max_value}})'` - Print table of users with UID >=1000 with header and formatted output, using colon as separator (`%-20s` mean: 20 left-align string characters, `%6s` means: 6 right-align string characters): -`awk 'BEGIN {FS=":";printf "%-20s %6s %25s\n", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s\n", $1, $4, $7}' /etc/passwd` +`gawk 'BEGIN {FS=":";printf "%-20s %6s %25s\n", "Name", "UID", "Shell"} $4 >= 1000 {printf "%-20s %6d %25s\n", $1, $4, $7}' /etc/passwd`