Questions tagged [gawk]

gawk (short for GNU awk) is a free implementation of awk with manifold useful extensions.

gawk (short for GNU awk) is a free implementation of awk with manifold useful extensions.

AWK is an interpreted programming language designed for text processing and typically used as a data extraction and reporting tool. It is a standard feature of most Unix-like operating systems.

Source: Wikipedia

See also .

Reference

981 questions
5
votes
5 answers

About awk and integer to ASCII character conversion

Just to make sure, is it really that using awk (Gnu awk at least) I can convert: from octal to ASCII by: print "\101" # or a="\101" A from hex to ASCII: print "\x41" # or b="\x41" B but from decimal to ASCII I have to: $ printf…
James Brown
  • 36,089
  • 7
  • 43
  • 59
5
votes
1 answer

asort(src,dest) to a multidimensional array

I'm trying to abuse asort() (just because) to copy an array src to array dest, no problem there: $ awk 'BEGIN { split("first;second;third",src,";") # make src array for testing asort(src, dest, "@ind_num_asc") # copy array to dest …
James Brown
  • 36,089
  • 7
  • 43
  • 59
5
votes
3 answers

How to use multiple passes with gawk?

I'm trying to use GAWK from CYGWIN to process a csv file. Pass 1 finds the max value, and pass 2 prints the records that match the max value. I'm using a .awk file as input. When I use the text in the manual, it matches on both passes. I can use…
Steve Kolokowsky
  • 423
  • 2
  • 12
5
votes
2 answers

In Awk, how to call a function by using a string name?

I'm seeking a way to call an awk function by name, i.e. by using a string that is user input. My goal is to replace a lot of code like this... if (text == "a") a(x) if (text == "b") b(x) if (text == "c") c(x) ... with any kind of way to dispatch to…
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
5
votes
3 answers

Parsing a .csv-like file in bash

I have a file formatted as follows: string1,string2,string3,... ... I have to analyze the second column, counting the occurrences of each string, and producing a file formatted as follows: "number of occurrences of x",x "number of occurrences of…
Luca
  • 801
  • 1
  • 6
  • 11
5
votes
1 answer

associative arrays in awk challenging memory limits

This is related to my recent post in Awk code with associative arrays -- array doesn't seem populated, but no error and also to optimizing loop, passing parameters from external file, naming array arguments within awk My basic problem here is simply…
Murgie
  • 137
  • 8
5
votes
2 answers

awk variable assignment statement explanation needed

ok, straight to the point, here is the codes, I formatted the codes a little to make it easy to read: awk '{ t=$0 ; $0=t ; $0=// ; print "$0=// ; value of $0 is ",$0 $0=t ; $0=/./ ; print "$0=/./ ; value…
Kent
  • 189,393
  • 32
  • 233
  • 301
5
votes
2 answers

How to supress default print in awk?

This is with gawk 4.0.0, running on Windows 7 with cygwin. The program is invoked like gawk -f procjournal.gawk testdata I have some data that looks like this: "Date";"Type";"Amount";"Balance" "6/11/2013 11:51:17 AM";"Transaction…
wades
  • 927
  • 9
  • 24
5
votes
3 answers

Picking up CSV fields by name using awk

Suppose I have a CSV file with headers of the following form: Field1,Field2 3,262000 4,449000 5,650000 6,853000 7,1061000 8,1263000 9,1473000 10,1683000 11,1893000 I would like to write an awk script which will take a comma-separated list of field…
merlin2011
  • 71,677
  • 44
  • 195
  • 329
5
votes
6 answers

Subtructing n number of columns from two files with AWK

I have two files with N number of columns File1: A 1 2 3 ....... Na1 B 2 3 4 ....... Nb1 File2: A 2 2 4 ....... Na2 B 1 3 4 ....... Nb2 i want a output where 1st column value from File1 will be subtracted from…
5
votes
2 answers

GAWK: Inverse of strftime() - Convert date string to seconds since epoc timestamp using format pattern

Gnu AWK provides the built in function strftime() which can convert a timestamp like 1359210984 into Sat 26. Jan 15:36:24 CET 2013. I couldn't find a function that would do this: seconds = timefromdate("Sat 26. Jan 15:36:24 CET 2013", "%a %d. %b…
try-catch-finally
  • 7,436
  • 6
  • 46
  • 67
5
votes
4 answers

transpose column and rows using gawk

I am trying to transpose a really long file and I am concerned that it will not be transposed entirely. My data looks something like this: Thisisalongstring12345678 1 AB abc 937 4.320194 Thisisalongstring12345678 1 AB efg 549…
user1269741
  • 437
  • 1
  • 5
  • 7
4
votes
5 answers

Find specific columns and replace the following column with specific value with gawk

I am trying to find all the places where my data has a repeating line and delete the repeating line. Also, I am looking for where the 2nd column has the value 90 and replace the following 2nd column with a specific number I designate. My data looks…
user1269741
  • 437
  • 1
  • 5
  • 7
4
votes
5 answers

Capture caret (^) with an awk regex

I have output with this format: /ignore-this/^/../I/want/this@ignore-this I am trying to use an awk regex to capture the following: ../I/want/this This wouldn't be particularly hard except that I cannot figure out how to properly escape the ^ so…
Rick Smith
  • 9,031
  • 15
  • 81
  • 85
4
votes
1 answer

Enable re-interval in gawk script

I create executable scripts for gawk by using the following #!: #!/usr/bin/gawk -f However if I want to enable interval regular expressions I cannot seem to add --re-interval or -W re-interval in the #!. #!/usr/bin/gawk --re-interval -f#Above…
Rob
  • 3,687
  • 2
  • 32
  • 40