Questions tagged [gawk]

gawk is the GNU implementation of awk. The awk utility interprets a special-purpose programming language that makes it possible to handle simple data-reformatting jobs with just a few lines of code.

The awk utility interprets a special-purpose programming language that makes it possible to handle simple data-reformatting jobs with just a few lines of code.

Links

256 questions
5
votes
2 answers

GNU awk wants to treat arguments as paths

I have this minimal awk example: #!/usr/bin/awk -f BEGIN { if (ARGC>1) a=ARGV[1] else a=5 } { print } Calling it with ls -l|./t.awk, results in: $ ls -l|./t.awk 2 awk: ./t.awk:4: fatal: cannot open file `2' for reading (No such file…
peterh
  • 9,731
5
votes
1 answer

Why can't a constant regular expression be put on the left side of an ~ operator in gawk?

Why can't I put a regular expression on the left side of the ~ operator when using gawk? For example, given the file below with fields delimited with tabs(\t): $ cat cats siberian 1970 73 2500 shorthair 1999 60 3000 longhair 1998 …
1
vote
2 answers

How do I split a file each time a regular expression occurs?

I'm trying to get gawk to split a text file into a different file each time a paragraph contains an occurrence of a code of the form "7-04/PNLP-000001". So, for instance, if the original text file contains the following: Proposición no de Ley…
edperez
  • 13
1
vote
1 answer

Can a string be used as index in array of arrays in gawk?

Let's look at this file: 9=foo 3=bar 84=baz 30=bin 71=bon 9=goo 3=gar 84=gaz 30=gin 71=gon 9=soo 3=sar 84=saz 30=sin 71=son Running this gawk line: gawk ' { split($0,arr) for(i=1;i<=length(arr);i++){ eq=index(arr[i],"=") …
Moshe
  • 322
1
vote
3 answers

How to replace the next record after a pattern matching using awk

How to replace(or modify) the next record after a pattern matching? Ex: 1 2 3 blah 4 replace this record 5 blah 6 replace this record 7 8 9 Here I want to skip or replace the fourth record and 6th record when the previous one record is "blah"
var
  • 11
0
votes
2 answers

Find and replace dot with text in column1 using gawk or awk

I have a csv as follows 1.2kbps,link1,description 1.2mbps,link2,description I would like to Find and replace a)dot and kbps with 000 in column1 b)dot and mbps with 000000 in column1 using gawk or awk and output should look like…
0
votes
1 answer

gawk columns from multiple files and add to a single text file

I have 50 sets of files containing 9 columns (sample shown in the attached picture). The files are named as ( 1) inputfile_1.assoc.logistic (2) inputfile_2.assoc.logistic etc…. The values in Columns 1, 2 and 3 are identical in all 50 files I…
Sam
  • 23
-2
votes
1 answer

Help reg to write gawk script

Need sample gawk to join two records with unique key $2.$1 has different entity eventhough $2 is key thats why there are ther are two different lines for same key I/p FIle not in sorted…
dileep
  • 9