Questions tagged [mawk]

Mawk is an implementation and fast processor of the AWK programming language.

Mawk is an implementation and fast processor of the AWK programming language. It can be compiled on many POSIX-like systems.

Binary mawk packages are available for many Linux distributions and for Mac OS (e.g., in MacPorts). Mawk is usually installed in addition to the default GNU/awk processor. The provided mawk command can be used as substitute for the default awk command to run AWK scripts. Some Linux distributions even symlink the default awk command to the mawk binary.

The main reason to use mawk instead of awk is performance [2,3,4].

20 questions
7
votes
5 answers

Can I pass an array to awk using -v?

I would like to be able to pass an array variable to awk. I don't mean a shell array but a native awk one. I know I can pass scalar variables like this: awk -vfoo="1" 'NR==foo' file Can I use the same mechanism to define an awk array? Something…
terdon
  • 3,260
  • 5
  • 33
  • 57
4
votes
1 answer

Bash commands piped to awk are sometimes buffered

System: Linux 4.13.0-43-generic #48~16.04.1-Ubuntu BASH_VERSION='4.3.48(1)-release' The command: while sleep 5 do date +%T done | awk -F: '{print $3}' Should print the 3rd field (seconds) of the "date" output, one line every 5 seconds. Problem:…
3
votes
1 answer

%a conversion specifier not recognized

POSIX Awk says: The printf statement shall produce output based on a notation similar to the File Format Notation used to describe file formats in this volume of POSIX.1-2008 (see XBD File Format Notation). And File Format Notation defines…
Zombo
  • 1
  • 62
  • 391
  • 407
3
votes
2 answers

Float comparison in awk and mawk

I cannot understand why the float number comparison does not work in mawk: mawk '$3 > 10' file.txt [...] 9_6_F-repl 24834 38.8699 9_6_F 56523 17.9344 9_7_F 3196 3.68367 9_9_F 2278 2.37445 9_annua_M-merg 122663 …
Tom S
  • 35
  • 3
3
votes
3 answers

How to define new commands or macros in awk

I like to define a new command that wraps an existing awk command, such as print. However, I do not want to use a function: #wrap command with function function warn(text) { print text > "/dev/stderr" } NR%1e6 == 0 { warn("processed rows:…
Juve
  • 10,584
  • 14
  • 63
  • 90
2
votes
1 answer

Why do several Linux distros ship mawk by default even though it is not POSIX compliant?

mawk is not POSIX compliant because it does not support POSIX EREs. To be precise, it does not support named character classes like [[:space:]] within its EREs, which are part of POSIX EREs. Both GNU awk and BusyBox awk do not seem to have this…
2
votes
2 answers

How to enable interval regular expression in mawk?

I hit an issue when I run the mawk on Ubuntu 1604: echo "123-456" | mawk '$0~/^[0-9]{3}/ {print $0}' The above command output nothing although the regular pattern matched actually. Then I tried to run the egrep with the same regular pattern: …
yw5643
  • 189
  • 1
  • 12
2
votes
0 answers

Mawk quantifier not working

I'm following an example in an awk book. I have the following bash script named "25regex.sh": #!/usr/bin/env bash # wh # wy …
builder-7000
  • 7,131
  • 3
  • 19
  • 43
2
votes
1 answer

What is the difference between the different awk versions?

I am reading through awk here but I am just wondering about the awk versions as I have encountered issues before with different awks. Below is a look at the different version I have. As I understand it there is awk, mawk and gawk. With gawk being…
HattrickNZ
  • 4,373
  • 15
  • 54
  • 98
2
votes
1 answer

Errors when executing switch/case in awk command in Ubuntu and Mac

I have a very strange problem when executing following code: awk '{ foo = 1; switch (foo) { case 1: i=i+1; break; } }' ./tcpheader.txt Getting following error: awk: syntax error at source line 1 context is { foo = 1; switch (foo) >>> { <<<…
Arsi
  • 163
  • 9
1
vote
3 answers

RS in awk language

I'm learning awk programming language and i'm stuck to a problem here. I've a file(awk.dat), having the following content: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas pellentesque erat vel tortor consectetur condimentum. Nunc…
A.K
  • 98
  • 1
  • 11
1
vote
2 answers

MAWK: Store match() in variable

I try to use MAWK where the match() built-in function doesn't have a third value for variable: match($1, /9f7fde/) { substr($1, RSTART, RLENGTH); } See doc. How can I store this output into a variable named var when later I want to construct my…
Lanti
  • 2,299
  • 2
  • 36
  • 69
1
vote
1 answer

AWK: Skip to next file

I have many data files to process but it isn’t necessary to process every record in every file.Is there a way to instruct awk to stop precessing the current file and skip to the next file?
Ren
  • 2,852
  • 2
  • 23
  • 45
1
vote
3 answers

AWK matching values in a column and performing calculation

I'm new at AWK and I'm trying to figure out an answer for my problem. I have a flat file with the following values: 403 | SanMateo | f | 2015-04-09 18:50:24.38 403 | SanMateo | t | 2015-04-09 18:45:24.36 403 | SanMateo | t | 2015-04-09…
NOOBIE
  • 43
  • 3
1
vote
1 answer

output piped to awk is not immediately handled

Consider the following dummy backup script: #!/bin/bash echo "rsync started" sleep 1 # rsync time echo "rsync completed" echo "starting upload" sleep 5 # upload time echo "upload completed" and the following minimal start…
muffel
  • 7,004
  • 8
  • 57
  • 98
1
2