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
3
votes
1 answer

gawk floating-point number localization

I want gawk to parse number using comma , as the decimal point character. So I set LC_NUMERIC to fr_FR.utf-8 but it does not work: echo 123,2 | LC_NUMERIC=fr_FR.utf-8 gawk '{printf ("%.2f\n", $1 + 0) }' 123.00 The solution is to specify option…
3
votes
1 answer

Two dimensional array handling in awk

I am trying a simple awk scripts for two-dimensional array which is given below: BEGIN{ b[1][1]=0 split("5 4 3 2",b[1]) print b[1][1] } This code snippet also mentioned in gnu gawk tutorial. But when I tried to run this I got syntax…
user976754
  • 361
  • 1
  • 4
  • 19
3
votes
6 answers

Using Awk to process a file where each record has different fixed-width fields

I have some data files from a legacy system that I would like to process using Awk. Each file consists of a list of records. There are several different record types and each record type has a different set of fixed-width fields (there is no field…
Dan Dyer
  • 53,737
  • 19
  • 129
  • 165
3
votes
1 answer

binary numbers in gawk

How can one specify a number as binary in gawk? According to the manual, gawk interprets all numbers as decimal unless they are preceded by a 0 (octal) or by a 0x (hexadecimal). Unlike in certain other languages, 0b does not do the trick. For…
user001
  • 1,850
  • 4
  • 27
  • 42
3
votes
4 answers

how to delete all columns containing a specific headline using AWK

I have a csv File which is of course comma separated and want to delete all the columns which have a specific title for example: voltage, current, power, voltage, current, power 2, 3, 6, 12, 12, 144 3, …
FE RY
  • 65
  • 7
3
votes
2 answers

awk extended pattern matching (embedding pattern matching in actions for already matched strings)

I want handle strings of the form: PREFIX_TYPE_N,DATA So, does the *awk (gawk, mawk, nawk) support including pattern matching in the action for already matched string? Something like this (of course, doesn't work for me): *awk 'BEGIN { FS="," } …
static
  • 8,126
  • 15
  • 63
  • 89
3
votes
2 answers

awk : if >=4 lines in a row begin with + or - don't print record

I'm trying to use awk to read a file and only display lines that do no begin with a + or - 4 or more times in a row. gawk would be fine too. Each grouping is separated by a blank line. Here's a sample from the file, these are the lines I do not want…
jonschipp
  • 781
  • 2
  • 9
  • 21
3
votes
3 answers

gawk running out of memory when going through large files: can i optimize my code?

I'm using gawk to go through a large textual corpus (about 3-4GB, a compilation of ebooks) in order to print out every association of 3 words that appears at least 3 times, in order to produce linguistic statistics. Here is the code: content of…
bobylapointe
  • 663
  • 1
  • 5
  • 12
3
votes
4 answers

Change a string in a file with sed?

I have a inputfile with template as shown below. I want to change the Version: using sed. Package: somename Priority: extra Section: checkinstall Maintainer: joe@example.com Architecture: i386 Version: 3.1.0.2-1 Depends: …
ShreyasD
  • 115
  • 1
  • 2
  • 10
2
votes
4 answers

Anyone know how to make a self-contained Awk/Gawk program on Windows

I'm using an awk script to do some reasonably heavy parsing that could be useful to repeat in the future but I'm not sure if my unix-unfriendly co-workers will be willing to install awk/gawk in order to do the parsing. Is there a way to create a…
wwilkins
  • 408
  • 4
  • 15
2
votes
4 answers

Print Field 'N' to End of Line

I would like to have help or direction on a problem I have in awk. I have a tab-delimited file with more than 5 fields. I want to output the fields excluding the first 5 fields. Could you please tell how to write an awk script to accomplish this…
jianfeng.mao
  • 945
  • 3
  • 13
  • 21
2
votes
2 answers

search through a file in the style of bash reverse-search-history

I'm trying to write a function which will search through a file in the same manner that reverse-search-history works. i.e. user starts typing in, prompt is updated with 1st match, hitting a special key rotates through other matches, hitting another…
Ben
  • 6,567
  • 10
  • 42
  • 64
2
votes
5 answers

how to find out common columns and its records from two files using awk

I have two files: File 1: id|name|address|country 1|abc|efg|xyz 2|asd|dfg|uio File 2(only headers): id|name|country Now, I want an output like: OUTPUT: id|name|country 1|abc|xyz 2|asd|uio Basically, I have a user record file(file1) and a header…
Saman
  • 333
  • 3
  • 9
2
votes
1 answer

gawk: why doesn't "next;" suppress lines matching a pattern?

I have the following awk program: /.*needle.*/ { if ($0 != "hay needle hay") { print "yay: ", $1; next; } print "ya2"; next; } { print "no"; next; } I run it as gawk -f test.awk < some.log > out.log in…
Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91
2
votes
1 answer

The role of `c&&!--c;` when used with `awk`

When learning to use awk, I found the expression awk 'c&&!--c;/regex/{c=N}' as a way to select and print the Nth line below the line matching the regex. I understand that c is initially equal to 0 so the first match isn't printed but despite having…
wclose
  • 23
  • 3