Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [mawk]

The tag has no usage guidance.

-1
votes
2answers
24 views

extract specific fields from a file using a character delimiter

I have a 1gb file and would like to get the third and fifth fields. The file is delimited by (,): input file: luis, jose, jesus atoche, mark, john 1,2,3,4,5 aa 1, bb 2, cc3, dd 4, ee5 output file: ...
0
votes
1answer
25 views

How to specify regex quantifiers with mawk?

I'm familiar with the concept of specified bounded regex quantifiers as follows: Quantifier Legend Example Sample Match {3} Exactly three times \D{3} ABC {2,4} ...
7
votes
4answers
416 views

Why does regex `“\.pdf”` match `/…/pdf…/…` in gawk, but not in mawk?

From How can I extract only the pid column and only the pathname column in the lsof output? awk '{ for (i=9; i<=NF; i++) { if ($i ~ "string" && $1 != "wineserv" && $5 == "REG" &...
1
vote
1answer
122 views

Unexpected split behavior

I read about Awk split behavior here: [...] the fs argument to the split function (see String Functions) shall be interpreted as extended regular expressions. These can be either ERE tokens or ...
1
vote
1answer
549 views

awk (mawk): regular expression compile failed (missing operand)

I want to use the following regex with awk to validate phone numbers: echo 012-3456-7890 | awk '/^\(?0[1-9]{2}\)?(| |-|.)[1-9][0-9]{3}( |-|.)[0-9]{4}$/ {print $0}' But I am getting the following ...
4
votes
2answers
721 views

Converting date timestamp from 12 hour into 24 using awk

I am working with a csv file which contains data in the following structure: "12345","BLAH","DEDA","0.000","1.111","2.22222","3.3333333,"15/12/2017 4:26:00 PM" I want to convert the 12 hour time ...
3
votes
1answer
405 views

Split out individual characters using the null string

I read this in the Gawk manual: GNU EXTENSIONS [...] The ability to split out individual characters using the null string as the value of FS, and as the third argument to split(). ...
3
votes
2answers
614 views

Portable check for array

Gawk has "isarray": if (isarray(x)) print "is array" else print "is scalar" However Mawk and "gawk --posix" do not: fatal: function 'isarray' not defined This can cause problems: x x[1] fatal:...
0
votes
2answers
397 views

awk find lines with two matches

File contains Today is 1 nice day This is a perfect day Tomorrow is 1/2 cool 1/2 hot day What is Toy Story Tonight is a dark night How do I find lines starts with "To" and end with "day" None of ...
3
votes
2answers
759 views

Combine two operations in one command - awk

I need to change - FROM Car Bus - TO Helicopter Airplane This two commands are sufficient. awk -i inplace '{sub(/Car/,"Helicopter")}1' file awk -i inplace '{sub(/Bus/,"Airplane")}1' file And ...
1
vote
1answer
118 views

awk - change value

File contains TIMEOUT=abc TIMEOUT=5 TIMEOUT= xTIMEOUT=5 I need to change from "TIMEOUT=5" to "TIMEOUT=9" This command works. But changes 4th line too, which is not desired awk '$0 ~ "TIMEOUT=...
1
vote
1answer
383 views

Need to filter the data on the basis of two column having many to one relationship using awk

I have a big file having 50s columns and 100K of rows delimited by |. Now $2(col 2) has multiple type of $1(col 1) value which means col 2 will be repeated. So I have sorted the file. I need now to ...
2
votes
1answer
149 views

Is there a reference for the assembler-like output produced by `awk -W dump`?

The command awk -W dump ... produces a dump of "assembler-like" code (as shown here [link], or by reading the man). Some of the instructions are easy to guess at their meaning such as jz, which is ...
12
votes
5answers
2k views

How to print own script name in mawk?

In bash $0 contains the name of the script, but in awk if I make a script named myscript.awk with the following content: #!/usr/bin/awk -f BEGIN{ print ARGV[0] } and run it, it will only print "awk"....
3
votes
1answer
3k views

Walking Multidimensional arrays in Mawk

I'm able to do this properly in gawk, but when I tried to post my code to the machine where it will run, I realized it was using mawk... $ cat multidim.gawk # test of multidimensional arrays // { ...
2
votes
1answer
2k views

Regular Expressions within a string in AWK using if/then control structure?

PROBLEM I want to specifically use AWK (GAWK, MAWK, whatever) in an AWK script to sum up the values in field 9 for every record that contains "runner__.jpx" (the underscores are placeholders for two ...
0
votes
3answers
503 views

Is it mandatory to have a variable in awk's first statement?

I am having some hard time with awk today. If I try to do: df|awk '{print $2; $some=$2; print $some}' It works as expected and I get the size of the disks twice but if I do: df|awk '{$some=$2; ...