Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

7
votes
3answers
2k views

String replacement using a dictionary

What is a good way to do string replacements in a file using a dictionary with a lot of substituend-substituent pairs? And by a lot, I actually mean about 20 – not much, but many enough so that I want ...
2
votes
5answers
4k views

How do I append/prepend a timestamp to grep output?

I am running a small linux server at home, and I am writing a script to log the temperature of the CPU cores every 5 seconds, but I need timestamps for it to be useful. So far I have something that ...
7
votes
1answer
270 views

Make bash exit != 0 when called by AWK and interrupted with ^C

I'm having an issue with the following piece of (G)AWK script: do { ... } while (system("sleep 10")) My intention is to break the loop when the user presses ^C during the sleep, but it's not ...
5
votes
3answers
773 views

Escape sequences passed as args to gawk not interpreted

I want to be able to pass an argument on the command line to gawk that is evaluated for escape sequences. The issue: $ gawk 'BEGIN { print ARGV[1]; }' '\t' \t Instead, I would like to get an actual ...
3
votes
4answers
3k views

Can I determine type of an awk variable?

I have the gawk version of awk. In this part of gawk manual, it is stated that awk variables have "attributes", which are used to determine how to treat them in various operations. For example, a ...
3
votes
2answers
633 views

Portable check for array

Gawk has "isarray": if (isarray(x)) print "is array" else print "is scalar" However Mawk and "gawk --posix" do not: fatal: function 'isarray' not defined This can cause problems: x x[1] fatal:...
1
vote
4answers
271 views

How shall I perform multiline matching and substitution using awk?

In a text file, ignoring any trailing whitespace at the end of each line, I assume that if a line is not ended with a digit, then there is a line break between the line and the next line, and I would ...
1
vote
1answer
1k views

How to use grep/awk/unix to match all lines from one file in another file, even if they are duplicates

I'm trying to retrieve the the matching lines from a file, however the file that has the "index" or list of matches to retrieve also has duplicate entries and I want to print out the duplicates as ...
7
votes
2answers
3k views

Batch rename image files by age plus add date and variable to filename

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking. After a photo shoot I come home with files that look like ...
2
votes
2answers
3k views

gawk: Summing floats formatted with comma separator

I'm trying to sum floats which use the comma as separator, and gawk does integer calculations. Here's the script: BEGIN { FS=";" OFS=";" CONVFMT = "%2.2f" } { print $1 print $2 print $1+$...
2
votes
1answer
1k views

Extract hostnames from non-hashed ssh known_hosts

I would like to extract hostnames/ips from .ssh/known_hosts file in all (known) format conditions: Hostname only hostname pubkey Hostname with ip: hostname,1.1.1.1 pubkey Hostname with ip that is not ...
1
vote
1answer
2k views

“^ backslash not last character on line” in gawk

I would like to match a number between / and , in each line, and increase it by 3. For example The Ubiquitous Backslash/49,Black becomes The Ubiquitous Backslash/52,Black My gawk command is: ...
1
vote
1answer
65 views

searching multiple files for a line with bigger number in column 3 of matched lines

I have multiple files with contents similar to: main file1: test01:6733:4370:5342 test02:7776:2018:1001 test03:9865:5632:1429 test04:8477:4757:1890 test05:8019:8860:5298 test06:5602:3100:6995 test07:...