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

gawk RS only at beginning of line with ^

Suppose I have multi line record with = as a record separator, but only if the = is the start of a line: $ cat file record 1, field 1 record 1, field 2 with a = in it record 1, field 3 = record 2, field 1 record 2, field 2 also with a = in it record…
dawg
  • 98,345
  • 23
  • 131
  • 206
2
votes
1 answer

Escaping parenthesis in gawk in windows

I am facing a rather strange issue when trying to escape a parenthesis in awk. My file has the following line 79-Au-196 isomer state population 0.153658 mb (m1 E= 0.5957MeV Jp=-12.0) So I want to extract column 5 (i.e. 0.153658). To do that I…
Thanos
  • 594
  • 2
  • 7
  • 28
2
votes
3 answers

How to use awk, to split a particular column (using delimiter), then add suffix and then merge?

In the data given below (which is tab separated): # data 1 xyz alfa x=abc;z=cbe;d=fed xt 2 xyz alfa y=cde;z=xy ft 3 xyb delta xy=def zf I want to add a suffix _LT in the elements (values of the variables) of 4th column after splitting…
everestial007
  • 6,665
  • 7
  • 32
  • 72
2
votes
1 answer

Print the next column after a match in gawk

I have a large file with multiple lines of text and columns, I have put a sample set below, the file comes from a windows server and the gawk is being run on windows fro within DOS. 170228 000005 0499 DE(N) SortationHandler.sortationio.Comm Sending…
Fabby
  • 71
  • 8
2
votes
2 answers

gawk behaviour I don't understand

I am trying to count the number of distinct values in field 12 of a file using gawk 4.1.4, and also count the number of times each of those values occurs. I have two short programs which are giving me different answers for the first question, and I…
Matti Wens
  • 740
  • 6
  • 24
2
votes
1 answer

My awk user function isn't working in a bash script

I am trying to write an awk script in ubuntu as a non-admin user. It takes four terminal statements and throws them into variables. Those variables then are sent to a function I made and it spits out an average number and prints it. Here is my…
Josiah
  • 37
  • 7
2
votes
1 answer

The "invisible" FS in a comma delimited array entry

Suppose I have: awk 'BEGIN{ c["1","2","3"]=1 c["12","3"]=2 c["123"]=3 # fleeting... c["1","23"]=4 c["1" "2" "3"]=5 # will replace c["123"] above... for (x in c) { print…
dawg
  • 98,345
  • 23
  • 131
  • 206
2
votes
1 answer

parse the output of mkvinfo in bash with gawk

I'm using the code described on this thread to parse mkvinfo output Bash script to extract information from a block of text spanning multiple lines my data: + Pistes du segment | + Une piste | + Numéro de piste : 1 (identifiant de piste pour…
Eeel
  • 117
  • 7
2
votes
1 answer

Is possible to set global AWK separator

Is it possible to set a global separator of awk, e.g., in a .conf file or environment var? I'm handling lot of files that using customized separator, don't feel right to manually set the FS and OFS every time. thanks.
StanleyZ
  • 598
  • 6
  • 22
2
votes
2 answers

How to use awk to select/remove fields from the end of a column after splitting?

In a file that has a particular column information I want to remove exactly 5 fields (i.e :PG:PB:PI:PW:PC (separator is ':') from the end of the lines, not from the…
everestial007
  • 6,665
  • 7
  • 32
  • 72
2
votes
1 answer

Grep - Input File is also the output file

I'm using command line grep -rI "TEXTSEARCH" . > output.txt and I get the error/prompt grep: input file ‘./output.txt’ is also the output Seems to work successfully but don't want to make extensive searching if this is something to worry about or…
Lucy Beale
  • 89
  • 2
  • 7
2
votes
2 answers

variable in awk regular expression

How to pass a variable to regular expression like this? match($0, /([^ ]+) (GET|POST|PUT|DELETE) ([^?]+)[^ ]+ HTTP\/[^ ]+ \"(VAR)\" ([^ ]+) ([^ ]+) ([^ ]+)/, matches)
exabiche
  • 2,895
  • 2
  • 17
  • 10
2
votes
1 answer

Real number on gawk

I am using gawk on a windows computer with cygwin. What i am trying to do is find min and max from three columns, two are lat and lon and the third column is the value. This is the code: echo off for /f "tokens=1,2,3 delims= " %%a in …
eliavs
  • 2,306
  • 4
  • 23
  • 33
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
4 answers

gawk use to replace a line containing a pattern with multiple lines using variable

I am trying to replace a line containing the Pattern using gawk, with a set of lines. Let's say, file aa contains aaaa ccxyzcc aaaa ddxyzdd I'm using gawk to replace all lines containing xyz with a set of lines 111\n222, my changed contents would…
Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69