Questions tagged [awk]
A pattern-directed scanning and processing language.
8,402 questions
1
vote
2
answers
131
views
find awk grep - search and replace & passing modified contents to awk to overwrite the existing file
I have a folder with many subfolders full of various Quarto(reg) files & in those files there are links that are located in varying positions in the file lines.
UPDATE ON 3 November 2025 in ...
3
votes
5
answers
611
views
awk - print the leading part of a matching pattern with back references
I want to print the part before a matching pattern with awk.
The original problem is, I want to get the service name from kubernetes pod names.
We have pods with names like some-name-and-foo-[[:alnum:]...
-1
votes
7
answers
605
views
Insert a character after every 2 character but discard first 2 characters
I want to print a colon after every 2 characters of alphanumeric Value and I found something like below. But I am not sure how to remove initial 2 characters from the output and what is the meaning of ...
5
votes
5
answers
365
views
Compare files and combine rows with matching values based on last column
I'm working with several files which come in bundle of four, across groups the bundels have the same number of columns; see below for an example showing the first four rows with header:
File1 has ...
-2
votes
4
answers
195
views
How to strip data from html using awk?
I'd like to retrieve data from here https://www.sbs.com.au/ondemand/tv-series/la-unidad/season-1. I wget the page to file.
The data I seek is in the form of (samples):
https://www.sbs.com.au/ondemand/...
2
votes
6
answers
672
views
Awk prints only first word on the field column
Please see my linux bash script below. I can't achieve my target output with my current code. It keeps reading the whole column 4.
input_file.txt:
REV NUM |SVN PATH | FILE NAME |DOWNLOAD ...
0
votes
5
answers
213
views
Rename a set of files according to a specific scheme, with rename back option
In Linux in a directory there are files, ls -1 shows me this output :
file1.1-rvr
file1.2-rvr
file1.3
file1.4-rvr
file1.5
file1.6-rvr
file2.1
file2.2
file3.1
file3.10
file3.2-rvr
file3.3-rvr
file3.4
...
1
vote
2
answers
93
views
Moving from single-purpose awk scripts to flexible function-based processing
A common way awk scripts are written is to use top-level pattern-action blocks.
The file would then consist of multiple top-level pattern-action blocks. Each
block would apply to input lines matching ...
3
votes
1
answer
269
views
AWK Syntax Error When Using Pattern-Action Blocks Inside Conditionals
Have written some code in an awk file. Basically the code captures lines starting with ### DK and returns the block between two blank lines. Would like the capability of either using a function or
...
2
votes
3
answers
224
views
How to extract specific fields from systemctl output for a custom report
I would like to build a report coming from the output of certain commands.
For instance, I have the output of such command:
systemctl --type=service --state=running |
grep -e cron -e apache2 -e ...
1
vote
3
answers
128
views
edit all the values in a specific column based on row numbers range
I have a PDB file (coordinates of atoms in a protein) on a Linux machine:
ATOM 1 N GLY A 1 0.535 51.766 5.682 1.00 0.00
ATOM 2 CA GLY A 1 -0.712 50....
2
votes
3
answers
325
views
Replacing a string in a file with GAWK issue
I have a program that will run a set of commands against new server installs and I need to change an entry in a file for each install. We need to change the default DNS from 127.0.0.X (which it ...
1
vote
2
answers
122
views
Filter for arbitrary AND patterns [duplicate]
Consider a command which takes arguments like this: cmd foo bar baz [arbitrary args...]. How do you build a filter of AND patterns based on those arguments?
Something like this pipeline of greps:
grep ...
3
votes
3
answers
520
views
How to generate two output files from if/else statement by using awk?
From the info below:
$ cat access.dat
2025/01/01T10:00:01 "GET" /path/resource/api1 User1 500
2025/01/01T10:00:01 "DELETE" /path/resource/api1 User1 503
2025/01/01T04:00:01 "...
7
votes
10
answers
3k
views
awk - how to print all fields after $5?
I have an output similar to
975 Jan/21 - 19:59:36 ### sed "/^#include_dir/a include_dir = 'conf.d'" /opt/db/data/efa_bauen_ni_14/postgresql.conf
986 Jan/21 - 20:04:21 ### grep -l "...
3
votes
2
answers
692
views
How to extract lines by condition from large CSV?
I have a CSV file with 100 million rows, approximately 60GB in size.
Now, I want to create another CSV from it but only take lines that match a certain condition: at the end of the CSV, there is an ...
0
votes
4
answers
342
views
Multiplying a column with a constant after a date in Bash
My file has two columns containing the date and the precipitation in mm for every day.
2024/01/01 5
2024/01/02 0
...
2024/12/26 15
2024/12/27 0
Now I will multiply the second column of the file after ...
-5
votes
1
answer
114
views
print two blocks outputs [closed]
I need to print outs of cert file blocks one by one
---BEGIN---
AA
BB
CC
--END CERTIFICATE---
--BEGIN---
AA
BB
CC
--END CERTIFICATE--
would need out put for running in a loop
some thing like
for i in ...
3
votes
4
answers
762
views
Convert pipe delimited column data to HTML table format for email
I am trying to convert delimited data format to html column table output for email printing and I am unsure how to use pipe delimiter as a separater for HTML tabular formatting.
Below is what I could ...
0
votes
2
answers
112
views
Adding up sizes of directories using bash is inconsistent
First, I got the total size of folder /my-downloads:
$ du -sh /my-downloads
304G /my-downloads
As you can see, it's 304G.
Then, I wanted to find out the total size of all immediate directories ...
2
votes
3
answers
115
views
Printing a specific section everytime search results are matched
I have a pretty basic text file on a Linux machine that has stuff like Chapters, Dialogues and References.
This is what it looks like
Chapter: 1 One: Birds and Trees
Birds are beautiful and trees ...
0
votes
4
answers
316
views
AWK command not working as expected giving & data as output
I have file where I need to find if some column is empty. File is delimited by ;
Some of data contains & in word and awk is command it not working for same .
Lets say I have file (...
-2
votes
2
answers
159
views
How to awk so that rest of the line stays intact?
I have line
* {@jira: PIVOT-9968} Provide a way to pass an `IMemoryCollector` to `IInternalMemoryMonitored#getMemoryStatistics(memoryCollector)` in order to prevent the count of duplicated blocks.
I ...
1
vote
4
answers
278
views
Trying to parse output of "lastb" command via awk, but when the userID field is blank, my variables are thrown off
I'm trying to pull the date and IP address from the output of lastb
I'm using: lastb | awk '{print $5,$6,$7,$3}'
The problem is that sometimes the first column (userID) of lastb is blank:
Data ...
2
votes
3
answers
490
views
Replace prefix string from lines in a file, and put into a bash array
In the file groupAfiles.txt are the lines:
file14
file2
file4
file9
I need a way to convert them to remove file and add /dev/loop and put them all in one line with a space between them.
/dev/loop14 /...