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

How do you skip characters with FIELDWIDTHS in GNU Awk 4.2?

GNU awk 4.2 was released and it contains many interesting features. One of them is: The FIELDWIDTHS parsing syntax has been enhanced to allow specifying how many characters to skip before a field starts. It also allows specifying '*' as the last…
fedorqui
  • 275,237
  • 103
  • 548
  • 598
3
votes
4 answers

matching a specific substring with regular expressions using awk

I'm dealing with a specific filenames, and need to extract information from them. The structure of the filename is similar to: "20100613_M4_28007834.005_F_RANDOMSTR.raw.gz" with RANDOMSTR a string of max 22 chars, and which may contain a substring…
RogerFC
  • 329
  • 3
  • 15
3
votes
1 answer

Convert timestamp to epoch in a file in-place

I have a tab delimited file with timestamp in third field which I need to change into epoch in bash. Sample Input: xyz@gmail.com SALE 2017-04-26 12:47:27 30.0 1 201704 xyz@gmail.com SALE 2017-04-26 12:46:15 20.0 2 …
Drunk Knight
  • 131
  • 1
  • 2
  • 14
3
votes
5 answers

AWK output to a delimited string

The following awk/\-0.81/ { print $0 }' fullYearData.txt successfully finds the instances of -0.81 In a long list of lines, like this: 2017-01-10 16:58 0.90 feet Low Tide 2017-01-10 22:54 2.10 feet High Tide 2017-01-11 07:19 -0.81 feet Low…
Dan
  • 527
  • 1
  • 7
  • 25
3
votes
5 answers

Can someone walk through this awk code for merging multiple files?

I'm using awk to merge multiple (>3) files, and I want to keep the headers. I found a previous post that does exactly what I need, but I don't quite understand what's happening. I was hoping someone could walk me through it so I can learn from it!…
moxed
  • 343
  • 1
  • 6
  • 16
3
votes
1 answer

What does ">!" do in bash or nawk?

I am translating a GAWK script into a C# program and I don't know what part of the GAWK script means. I've got the rest of the script figured out but I can't seem to find where to look for the rest of these commands. I don't have an example of…
Kaden.Goodell
  • 162
  • 1
  • 8
3
votes
3 answers

AWK print column from a specific row if conditions are met

I want to use 'awk' to extract specific information from a formatted file such that: If the row has 2 fields, the first column (100) is printed and the second column (2) represents "X" pairs of lines that follow If the row corresponding to NR +…
platypus106
  • 33
  • 1
  • 5
3
votes
1 answer

Top awk result cut off with count condition

I have a list of student records, grades, that I want to sort by GPA, returning the top 5 results. For some reason count<=7 and below cuts off the top result. I can't figure out why that is. Also, is there a more elegant way to remove the first…
Jo P
  • 33
  • 2
3
votes
1 answer

%a conversion specifier not recognized

POSIX Awk says: The printf statement shall produce output based on a notation similar to the File Format Notation used to describe file formats in this volume of POSIX.1-2008 (see XBD File Format Notation). And File Format Notation defines…
Zombo
  • 1
  • 62
  • 391
  • 407
3
votes
0 answers

gawk FPAT doesn't override FS

I have a csv file with the format : "a b c","d","e","f", "bla","bla","bli","fff" The FPAT as given here by the official GNU site stipulate that "Assigning a value to FPAT overrides field splitting with FS and with FIELDWIDTHS." However, I have…
Hicham
  • 81
  • 6
3
votes
2 answers

AWK program to find the average rainfall of three states

I want to find the average rainfall of any three states say CA, TX and AX for a particular month from Jan to Dec . Given input file delimited by TAB SPACES and has the format city name, the state , and then average rainfall amounts from January…
Eternal Learner
  • 3,800
  • 13
  • 48
  • 78
3
votes
1 answer

One nearest neighbour using awk

This is what I am trying to do using AWK language. I have a problem with mainly step 2. I have shown a sample dataset but the original dataset consists of 100 fields and 2000 records. Algorithm 1) initialize accuracy = 0 2) for each record r …
Murlidhar Fichadia
  • 2,589
  • 6
  • 43
  • 93
3
votes
2 answers

Min-Max Normalization using AWK

I dont know Why I am unable to loop through all the records. currently it goes for last record and prints the normalization for it. Normalization formula: New_Value = (value - min[i]) / (max[i] - min[i]) Program { for(i = 1; i <= NF; i++) { …
Murlidhar Fichadia
  • 2,589
  • 6
  • 43
  • 93
3
votes
2 answers

Bash and awk - how to pass a variable to awk when doing multiline pattern maths?

I'm using AWK for multiline matching with patterns. Example: awk '/"ip": /,/"id": /' I would like to pass an argument to AWK when I know the ip, so that it would return the lines that include the specified IP. Example: awk '/"ip": "$IP"/,/"id":…
Mindaugas Bernatavičius
  • 3,757
  • 4
  • 31
  • 58
3
votes
3 answers

Substitute Array Elements into Regular Expression Statements / Variable Names

Been wondering if this is doable in AWK for some time but always worked around it in the past. Below I initialize an array with 3 months of the year... for readability I ommited the other 9 months. These months are then used in the if-statement as…
jparanich
  • 8,372
  • 4
  • 26
  • 34