34,382 questions
Score of 0
1 answer
140 views
unexpected gawk: printf output [closed]
using gawk under windows cmd.exe with the following as the awk program
{ printf "%s,", $0 }
overwrites the first letter of $0 with , for any input you care to try.
I'm expecting to see $0 ...
Score of 9
10 answers
936 views
Remove multiple occurrences of similar lines except the last
I have a file where a pattern repeats a various number of times between lines that are relevant. I want to keep only the last of the lines that repeat in each occurrence of the repetition. This is ...
Score of -8
4 answers
224 views
How to append lines from a file into new file which name bases on the content?
I have a file - around 75k lines - with this content:
2022-02-09 15:00 Free: 123
2023-11-10 16:00 Free: 170
2024-04-28 17:00 Free: 105
2025-12-19 18:00 Free: 3001
2026-07-08 19:00 Free: 2576
Each ...
Score of 1
2 answers
88 views
Why am I forced to use gawk paragraph mode here?
I have a text file consisting of "text block", the individual blocks are separated from each other by one or more newlines. I wanted to count the number of blocks. My first attempt went like ...
Score of 4
3 answers
205 views
force number of digits in awk output (no printf)
the problem is that awk transforms any roundable float into integers: 1.000 -> 1
for example:
cat <<EOF | awk -v CONVFMT=%.06f '{$1=$1*2; print}'
0.000 some stuff
1.000 other different ...
Score of 0
2 answers
127 views
Bash: printing lines of file until SPECIAL_LINE (not included)
I came up with this:
awk '{print}/SPECIAL_LINE/{exit}' file.txt | head -n -1
Any other suggestions?
Maybe it could be more elegant.
[UPDATE]
Thank you very much everyone! I'd like to point out my ...
Score of 4
3 answers
340 views
Problems redirecting awk output to a file in R
I have a text file (data.txt)
lala=something
dada=somethingelse
stuffwithoutequalsign
otherstuffwithoutequalsign
I am parsing it in R/Rstudio/Win11 using system call to awk (gawk 5.3.0 installed), ...
Score of 3
6 answers
329 views
Merging the headers then concatenate the records of a huge number of text files
I would like to fuse a huge number of big (~1GiB) text files in VCF (Variant Call) Format. The operation requires to read all the headers first (in order to generate and output a new one) and then ...
Score of 8
7 answers
654 views
Extract selected data from multiple lines of text
Here is the output of my curl command (print headers only):
HTTP/1.1 200 OK
Server: CacheHTTPd v1.0
Date: Thu, 08 Jan 2026 19:21:11 +0000
Content-Type: application/octet-stream
Content-Length: ...
Score of 8
4 answers
244 views
Ansible way to convert stdout lines to a dictionary keeping multilines under the same key
Given the following text:
Param1 : Value1
Param2 : Value2
Param3 : Value3a
: Value3b
: Value3c
Param4 : Value4
I would like to obtain the following Ansible result dict of strings or ...
Score of 1
2 answers
139 views
awk to get certain next lines when a pattern is matched
I have an input as the following.
0:4:1 untagged 192.168.20.11 255.255.255.0 0.0.0.0 0 0.0.0.0 3205
- 10 192.168.10.11 255.255.255.0 0.0.0.0 0 0.0.0.0 3205
- ...
Score of 0
2 answers
77 views
Find IP addresses with awk matching two strings
I'm trying to get all the IP addresses with response 404's from our Apache web server log file.
This is what I have:
awk '($7 == "404") {print $1,$5}' /var/log/404.log | sort -n > ip.list
...
Score of 0
2 answers
103 views
using persistent-memory gawk how variables can created to be local and issolated from other execution instances?
The idea of Persistent-Memory gawk is fabulous because it improves the performance, size, and clarity of many scripts on static and reference data.
However, I have a significant problem in adopting ...
Score of 6
4 answers
268 views
awk command to subtract constant from a column and print results
I was working on a one-liner to subtract a constant value (e.g. 100 in this case) from a specific column using awk. So far I can manage to get to where I can print the last iteration only – which ...
Score of 6
3 answers
328 views
Does the awk standard unambiguously define that `a || b=c` is (or is not) valid?
Most awk implementations I have tried (gawk, mawk, original-awk, bsd awk) allow the form: a || b = c
The exception seems to be busybox which returns a syntax error unless parentheses are used:
$ ...