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

extract data from text files

I have some text files as shown below. I would like to extract the numbers of second column only if the 4th column has 5 or more continuous numbers with >0. file1.txt 68.2 408 68.2 0 33.4 409 30.3 3.1 12.6 410 7.5 …
manual
  • 23
  • 2
2
votes
2 answers

how to extract data from trace files using awk and xxd

I am trying to extract data from a trace files and calculate the sum. For a single file, the following command works : cat avg.txt| gawk '{T+=$1} END {print T "\n"}' But when I try using it with xargs command, as I have to do the same operation…
2
votes
1 answer

gawk 4 - Use variable as an array index

Is it possible to use a variable as the index to a true multidimensional array? I have an gawk 4.1.1 script that runs through Cisco configuration files, and I want to create an array that looks like: myarray[sitecode][switchname] Where sitecode and…
refriedjello
  • 657
  • 8
  • 18
2
votes
1 answer

counting unique numbers from each file

I have some files named file1, file2, file3......etc. These files are in a folder f1. The content of the files are shown below. I would like to count the unique pairs of first column in each file. some files have no data. It is printed as zero. How…
2
votes
1 answer

Join two tables with AWK, one from stdin, other from file

I have two tab-delimited files: file tmp1.tsv: 1 aaa 2 bbb 3 ccc 4 ddd 5 eee file tmp2.tsv: 3 2 4 I want to get this: 3 ccc 2 bbb 4 ddd Using following routine: $ cat tmp2.tsv | awk -F '\t' tmp1.tsv I know…
Kostya
  • 1,536
  • 1
  • 13
  • 22
2
votes
4 answers

extract pattern data using gawk/awk

I have a input text like below: 10779: (255,255, 0,255) #FFFF00 yellow 338: (255,238,125,255) #FFEE00 srgba(255,238,125,1) 180: (238,221, 0,255) #EEDD00 srgba(238,221,0,1) .... I wish the output is 255,255,0,255 255,238,125,255 …
realmq
  • 429
  • 4
  • 18
2
votes
3 answers

replace 4th column from the last and also pick unique value from 3rd column at the same time

I have two files both of them are delimited by pipe. First file: has may be around 10 columns but i am interested in first two columns which would useful in updating the column value of the second file. first file detail:…
chidori
  • 1,052
  • 3
  • 12
  • 25
2
votes
4 answers

AWK: Is there a way to limit the width of an output field?

I need to limit the final size of a field to 2048. I could probably use: ACTION_PARAMETER=substr($2,1,2048); But is there a better way?
D-Klotz
  • 1,973
  • 1
  • 15
  • 37
2
votes
2 answers

AWK is it possible to read a time field and use it for sorting?

I have two files and I need to sort and merge the rows based on the time column: File A: "2014-02-26 16:03:04" "Login Success|isNoSession=false" id=csr,ou=user,dc=openam,dc=forgerock,dc=org 7efb2f0e035a0e3d01 10.17.174.30 INFO …
D-Klotz
  • 1,973
  • 1
  • 15
  • 37
2
votes
6 answers

Make all entries in an ascii file in one column in awk

I have the following file CHO 1 4096 26 20 0 0 0 0 0 0 0 0 0 0 0 0 0 3 5 15 8 14 9 7 13 10 12 9 5 3 3 2 2 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 6 8 5 5 7 13 13 33 23 29 44 51 56 42…
Thanos
  • 594
  • 2
  • 7
  • 28
2
votes
2 answers

AWK explanation example

I have a file: AWK question about the example This command that works well: awk '{ gsub(/...../, "&\n" ) ; print}' file AWK q uesti on ab out t he ex ample Why this command does not print the same result? awk '{ gsub(/.{5}/, "&\n" ) ; print}'…
Tedee12345
  • 1,182
  • 4
  • 16
  • 26
2
votes
2 answers

Merging rows in a file | Performance Improvement

I have a file in which I have to merge 2 rows on the basis of: - Common sessionID - Immediate next matching pattern (GX with QG) file1: session=001,field01,name=GX1_TRANSACTION,field03,field04 session=001,field91,name=QG …
Vipin Choudhary
  • 331
  • 1
  • 2
  • 16
2
votes
5 answers

How this AWK is replacing an IF?

I've reviewing some bash scripts written by other people at work and I found this line that I'm trying to understand [[ $(awk 'BEGIN{print ('$CAPACITY'>=0.9)}') -eq 1 ]] && echo "Capacity at 90 Percent" Is my understanding that this line is…
andresg3
  • 343
  • 2
  • 6
  • 20
2
votes
1 answer

gawk do twice asorti() error

I'm trying to sort an array (dictionary) by their values ​​while maintaining the correct keys. I have a problem. I have written a code that performs the task, but when I call the function repeatedly printTop only works well the first call. My gawk…
VíctorUce
  • 23
  • 4
2
votes
2 answers

Lookup and Replace with two files in awk

I am trying to correct one file with another with a single line of AWK code. I am trying to take $1 from FILE2, look it up in FILE1, get the corresponding $3 and $4. After I set them as variables I want the program to stop evaluating FILE1, change…
jeffpkamp
  • 2,732
  • 2
  • 27
  • 51