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

How to filter logs easily with awk?

Suppose I have a log file mylog like this: [01/Oct/2015:16:12:56 +0200] error number 1 [01/Oct/2015:17:12:56 +0200] error number 2 [01/Oct/2015:18:07:56 +0200] error number 3 [01/Oct/2015:18:12:56 +0200] error number 4 [02/Oct/2015:16:12:56 +0200]…
fedorqui
  • 275,237
  • 103
  • 548
  • 598
2
votes
1 answer

How to replace Nth match in a line with awk

In sed you can replace the Nth match using /N (solved so long ago): $ sed 's/you/ME/1' <<< "hello you are you" # 1 is superfluous here, though hello ME are you $ sed 's/you/ME/2' <<< "hello you are you" hello you are ME I am trying to accomplish…
fedorqui
  • 275,237
  • 103
  • 548
  • 598
2
votes
1 answer

Count the number of replacements of GNU awk gensub

I have the following bash code using gawk gsub: replacedCount=$(gawk -v FILE_TMP="$FILE_TMP" -v OLD="$OLD" -v NEW="$NEW" '{ num += gsub( OLD, NEW ); print $0 > FILE_TMP; } END { print num }' "$FILE") It replaces all instances of OLD with NEW and…
Turtle
  • 23
  • 4
2
votes
3 answers

awk replacing text but not for the last line

i tried the awk liner below(on windows command-prompt):not working properly gawk -v var="hot" "{ if(!NR){gsub(/cool/,var,$0) ;print} else{print}}" awk_test input file is below this is a cool jack this nota cool kack this obviously a cool jack…
Vijay
  • 65,327
  • 90
  • 227
  • 319
2
votes
2 answers

awk read float precision: cannot read small floats, e.g. 4e-320

I cannot get awk or gawk to read small floats in scientific notation and interpret them correctly as floating point numbers. I just want to output numbers above a small threshold with awk. Example: consider the following…
cmo
  • 3,762
  • 4
  • 36
  • 64
2
votes
1 answer

awk variables and printf

I have a CSV file like…
sasieightynine
  • 434
  • 1
  • 5
  • 16
2
votes
1 answer

gawk printf missing characters

I'm trying to create a script in (g)AWK in which I'd like to put the following EXACT lines at the beginning of the output text file:
sasieightynine
  • 434
  • 1
  • 5
  • 16
2
votes
1 answer

gawk - sorting values from array of arrays

Using gawk 4 to build arrays of arrays and need to figure out percentile data from it. Need to sort values in ascending order which doesn't appear possible using asort when working with multidimensional arrays. Some of my values will be duplicate…
refriedjello
  • 657
  • 8
  • 18
2
votes
2 answers

How to convert a date string to timestamp in gawk?

I am scanning through a log file formatted like this: 76.69.120.244 - - [09/Jun/2015:17:13:18 -0700] "GET /file.jpg HTTP/1.1" 200 22977 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)…
Marc Fowler
  • 913
  • 1
  • 11
  • 22
2
votes
1 answer

using awk for subtraction

Similar post here: awk if statement with simple math Below is great but now I need to subtract 20 from field $4 if it's less than 20 and if its greater than 20, field five can be set to…
Registered User
  • 255
  • 4
  • 12
2
votes
2 answers

AWK - Search for a pattern-add it as a variable-search for next line that isn't a variable & print it + variable

I have a given file: application_1.pp application_2.pp #application_2_version => '1.0.0.1-r1', application_2_version => '1.0.0.2-r3', application_3.pp #application_3_version => '2.0.0.1-r4', application_3_version =>…
ARL
  • 986
  • 2
  • 12
  • 25
2
votes
5 answers

awk if statement with simple math

I'm just trying to do some basic calculations on a CSV file. Data: 31590,Foo,70 28327,Bar,291 25155,Baz,583 24179,Food,694 28670,Spaz,67 22190,bawk,4431 29584,alfred,142 27698,brian,379 24372,peter,22 25064,weinberger,8 Here's my simple awk…
Registered User
  • 255
  • 4
  • 12
2
votes
1 answer

awk unmatched with blank file

Recently I've encountered a strange behavioral problem with awk say I have two files one with blank file & the another is with populated data so let me apply a simple unmatched code awk -v var=0 'NR==FNR{a[$var]++;next} !($var in a)' file1…
bongboy
  • 147
  • 1
  • 15
2
votes
2 answers

how to use regular expression in awk or sed, for find all homopolymers in DNA sequence?

Background Homopolymers are a sub-sequence of DNA with consecutives identical bases, like AAAAAAA. Example in python for extract it: import re DNA = "ACCCGGGTTTAACCGGACCCAA" homopolymers = re.findall('A+|T+|C+|G+', DNA) print homopolymers ['A',…
Jose Ricardo Bustos M.
  • 8,016
  • 6
  • 40
  • 62
2
votes
3 answers

awk to process the first two lines then the next two and so on

Suppose i have a very file which i created from two files one is old & another is the updated file by using cat & sort on the primary key. File1…
bongboy
  • 147
  • 1
  • 15