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
6 answers

rearrange data on a file (NOT a direct transpose)

I have a file (more than 2.5k lines) like this: NAME YEAR A B C JOHN Y1 10,00 19,00 65,00 JOHN Y2 11,00 23,00 64,00 JOHN Y3 12,00 33,00 34,00 JOHN Y4 13,00 34,00 32,00 PAUL Y1 14,00 43,00 23,00 PAUL Y2 15,00 90,00 34,00 PAUL Y3 16,00 32,00…
silvio
  • 85
  • 6
2
votes
2 answers

Finding blank lines in a file with awk

My apologies for such a rudimentary question, but I am attempting to count the number of blank lines in a text file with awk. This is NOT a homework assignment. Windows 10. Gawk 4.1.3 BEGIN { x=0 } /^$/ { x=x+1 } END { print "I found " x "…
CaitlinG
  • 1,955
  • 3
  • 25
  • 35
2
votes
2 answers

Update tab-delimited file in-place with gawk

I am trying to add field headers to a file in-place using gawk. The input file is tab delimited so I added that to the command. If I substitute gawk -i inplace with just awk the command runs but the file is not updated. I know awk doesn't have an…
justaguy
  • 2,908
  • 4
  • 17
  • 36
2
votes
1 answer

get paragraph with awk, and start-of-line regexp

I use awk to get paragraphs from a textfile, like so: awk -v RS='' -v ORS='\n\n' '/pattern/' ./textfile Say I have the following textfile: aaa bbb ccc aaa bbb ccc aaa bbb ccc aaa ccc bbb aaa ccc bbb aaa ccc ccc bbb aaa ccc bbb aaa ccc bbb…
Ulli
  • 21
  • 2
2
votes
1 answer

AWK how records and fields are executed and read

I am getting the right result for the awk program below. But I dont understand how does AWK process lines of code for the below program : { for(i = 1; i <= NF; i++) { if (min[i]==""){ print "initial min " $i; min[i]=$i;} #line1 if…
Murlidhar Fichadia
  • 2,589
  • 6
  • 43
  • 93
2
votes
3 answers

AWK - What does !i++ do

I have the following section of code: if (substr($12,match($12,":")+1,match($12,")")-15) == "TelegramHandlerECHLane") { $11 ~ /ms/ ( SUM10 += $11) !i++ (min = $11) !i++ (max = $11) { …
glly
  • 107
  • 7
2
votes
3 answers

awk group by multiple columns and print max value with non-primary key

i'm new to this site and trying to learn awk. i'm trying to find the maximum value of field3, grouping by field1 and print all the fields with maximum value. Field 2 contains time, that means for each item1 there is 96 values of field2,field3 and…
foxx
  • 23
  • 1
  • 5
2
votes
2 answers

bash group times and average + sum columns

I have a daily file output on a linux system like the below and was wondering is there a way to group the data in 30min increments based on $1 and avg $3 and sum $4 $5 $6 $7 $8 via a shell script using awk/gawk or something similar? 04:04:13…
user1999357
  • 113
  • 1
  • 2
  • 11
2
votes
2 answers

count number of values in each field in awk, output table

I'm trying to count the number of elements/words present in each field of a big table. Fields are delimited by whitspaces, and field elements ("words") by commas. The table also contains empty fields (e.g. two or more consecutive whitespaces), which…
xgrau
  • 299
  • 1
  • 2
  • 11
2
votes
4 answers

AWK - if not in array

I have two files separated by tabs. Comparing files by the first field, I need to print the line where the field does not match. But the line to be printed is from the file (file1) File1: adu adu noun singular n/a n/a nominative aduink adu…
Firefly
  • 449
  • 5
  • 20
2
votes
2 answers

Closest value different files, with different number of lines and other conditions ( bash awk other)

I have to revive and old question with a modification for long files. I have the age of two stars in two files (File1 and File2). The column of the age of the stars is $1 and the rest of the columns up to $13 are information that I need to print at…
Nikko
  • 517
  • 3
  • 7
  • 19
2
votes
2 answers

gawk - suppress output of matched lines

I'm running into an issue where gawk prints unwanted output. I want to find lines in a file that match an expression, test to see if the information in the line matches a certain condition, and then print the line if it does. I'm getting the output…
Boncrete
  • 146
  • 1
  • 5
2
votes
2 answers

GAWK premature EOF with getline

Here's the deal: I need to read a specific amount of bytes, which will be processed later on. I've encountered a strange phenomenon though, and I couldn't wrap my head around it. Maybe someone else? :) NOTE: The following code-examples are…
Dan
  • 630
  • 5
  • 8
2
votes
3 answers

AWK sort array of strings by string length

The array is obtained from a split(); x=split(A,B). I need to sort the array by the length of the strings, from smallest to largest. Current order: B[1]=alnis; B[2]=nis; B[3]=connis Desired order: B[1]=nis; B[2]=alnis; B[3]=connis I've tried it…
Firefly
  • 449
  • 5
  • 20
2
votes
3 answers

awk print to the top of the output file

I have an input text file with paragraphs in it, which are separated by 3 empty lines. Example: P1 P1 empty line here empty line here empty line here P2 P2 empty line here empty line here empty line here P3 P3 empty line here empty line here empty…
sasieightynine
  • 434
  • 1
  • 5
  • 16