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
4
votes
2 answers

awk sort multidimensional array

GNU awk supports multidimensional arrays: q[1][1] = "dog" q[1][2] = 999 q[2][1] = "mouse" q[2][2] = 777 q[3][1] = "bird" q[3][2] = 888 I would like to sort the "second column" of q such that I am left with: q[1][1] = "mouse" q[1][2] = 777 q[2][1] =…
Zombo
  • 1
  • 62
  • 391
  • 407
4
votes
3 answers

How to fetch IP address from a log file?

I am trying to split the IP address into columns, I am new to this and have no idea where to start, hope you can give me a bit of an insight. My log file crawl-66-249-64-13.googlebot.com - - [17/Oct/2004:04:40:15 +0100] "GET /robots.txt HTTP/1.0"…
user2160949
  • 131
  • 2
  • 9
4
votes
7 answers

Regex with awk or gawk

I'm a beginner user of awk/gawk. If I run below, the shell gives me nothing. Please help! echo "A=1,B=2,3,C=,D=5,6,E=7,8,9"|awk 'BEGIN{ n = split($0, arr, /,(?=\\w+=)/) for (x=1; x
Jaeh
  • 609
  • 1
  • 6
  • 19
4
votes
3 answers

awk not rounding with OFMT and $0

I'm printing an array with 100 columns and I would like all columns to have 2 decimals. I would like to use print $0 and not have to individually specify the format for all columns. OFMT does seen to work with $0: echo '0.77767686 0.76555555…
user1629165
  • 81
  • 2
  • 6
4
votes
2 answers

Why does (g)awk reverse these lines of output?

So, I'm seeing this output and I'm a bit surprised: $ echo "a,b,c,d,e,f,g" | cut -d, -f-4 a,b,c,d $ echo "a,b,c,d,e,f,g" | cut -d, -f6- f,g echo "a,b,c,d,e,f,g" | awk '{ print $0 | "cut -d, -f-4"; print $0 | "cut -d, -f6-"; }' f,g a,b,c,d (As a…
FatalError
  • 52,695
  • 14
  • 99
  • 116
3
votes
3 answers

command line pivot

I've been hunting around the past few days for a set of command line tools, a perl or an awk script that allow me to very quickly transpose the following data: Row|Col|Val 1|A|foo 1|B|bar 1|C|I have a real 2|A|bad 2|C|hangover into…
Josh
  • 177
  • 1
  • 11
3
votes
5 answers

Why can't I escape quote in gawk?

I'm trying to do the following, but either I'm way too tired and can't think, or something weird is hapening with the escapes: scanimage -L | gawk '/N650U/ {print gensub("[\'`]", "", "g", $2)}' pipe bquote>
Masse
  • 4,334
  • 3
  • 30
  • 41
3
votes
3 answers

Gawk print largest value from each column

I am writing a awk script that takes some columns of input in a text file and print out the largest value in each column Input: $cat numbers 10 20 30.3 40.5 20 30 45.7 66.1 40 75 107.2 55.6 50 …
BillPull
  • 6,853
  • 15
  • 60
  • 99
3
votes
2 answers

AWK user-defined function - a new syntax?

When looking for a quick way of right trimming a text string, I found the following wiki page: Wiki trimming page In the chapter about AWK it gives 2 sets of examples: ltrim(v) = gsub(/^[ \t]+/, "", v) rtrim(v) = gsub(/[ \t]+$/, "", v) trim(v) =…
piquet00
  • 31
  • 1
3
votes
2 answers

A Perl or Gawk script that returns a Keyword, the word before, and the word after?

I need a simple script to run in Windows that searches large xml files for a keyword, then returns the word before it, the keyword, and the word after. For example: "How can I extract keywords in context" I want: "extract keywords in" I'm a novice…
Rich Mason
  • 33
  • 2
3
votes
2 answers

Awk match() - multiple per line

I'm using the match() function in gawk to grab links out of an HTML file.. the regular expression is something like this: match($0, /(
jonseager
  • 317
  • 2
  • 8
3
votes
1 answer

Why does '-1' not work in Awk but '(-1)' does?

I was doing some data filtering and noticed something a bit strange. As we all know, awk '1' is short for awk '{print $0}', since 1 evaluates to True and triggers that default action on Awk, which consists on printing the current record. Similarly,…
fedorqui
  • 275,237
  • 103
  • 548
  • 598
3
votes
1 answer

How to get size of array in AWK?

I have declared array by splitting string like below. names = "Dhana,Subha,Siva" n=split(names,name_arr,","); I want to print the size of array here without using variable 'n'? is there any way similar to name_arr.length or name_arr.size() ?
Dhanabalan
  • 572
  • 5
  • 19
3
votes
3 answers

awk matching regex and replace the symbol

Hi I have a file which has lines as below ( below is a single sample line) Running Test File: /home/rsc_app|06_2BIN/08_payfacil/01_5BIN/003_nt2bnet_Acq004601_0100_0420_mc.utt|Test Result | Pass | MIG_NT2_EP2 CIS_EP1|0403319| what i am trying to…
Abrar Ahamed
  • 199
  • 11
3
votes
1 answer

How to "roll back" a getline call?

If I use getline in my awk script, it reads the next line from the stream and updates the $0 and NR variables (as it should). Is there a way to un-getline? For example, I want to use getline to determine the EOF and then take an action on that. But…
ysap
  • 7,723
  • 7
  • 59
  • 122