Questions tagged [awk]
AWK is a text-processing language. It is mainly used to manipulate and process structured data, and to generate reports.
643 questions
2
votes
2
answers
228
views
How to change a string on the line for a specific parameter (we don’t know the string value) in a Linux Bash script?
Please note that I have done some search and tried different solutions with sed/awk and nothing worked. I'm stuck, so I posted the question here requesting your help.
Let’s say that there's a generic ...
3
votes
4
answers
371
views
How to extract one part of a paragraph if a previous line matches an expression?
I’m trying to get the time delta value for a given host (I have either its hostname or IP address) from the following text:
--------------------------------------------------------------
CentMgmt::...
4
votes
6
answers
1k
views
How can I replace one space with N spaces?
There are lots of SE posts about replacing multiple spaces with a single space, but seemingly none about replacing one space with multiple spaces.
Input data:
$ head -n20 $X | paste -sd' \n'
...
2
votes
2
answers
189
views
Multiple result lines from bash feeding into multiple variables
I am new to Bash and wanted some help.
I have a command which produces four lines and I would like these lines to be fed to four variables, so i can use them in the next command. could someone please ...
0
votes
4
answers
161
views
How to print all lines matching the pattern 1 and print only line with pattern 2 which is the line before line containing pattern 1?
Say I have two patterns (pattern 1 and pattern 2) Want to print all lines matching the pattern 1 and print only line with pattern 2 which is the line before line containing pattern 1:
eg: I have a ...
3
votes
3
answers
313
views
How to print between " " value from XML file?
I'm using the following command combination to print value from an XML file to another file:
grep -Po '<add key="WorkstationID" value="\K[^"]+' web.config.txt | awk '{print &...
3
votes
1
answer
646
views
How does GNU Awk match expressions with capture groups?
I am testing this on a pretty old Debian 10 system using
GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
in
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Both awk and gawk commands ...
2
votes
4
answers
564
views
print (only) line preceding a match
Consider a text-input that looks like this:
a
b
pattern
c
pattern
d
e
pattern
a
--
pattern
z
I would like to get only the lines that precede a match.
E.g. if my pattern is pattern, the output should ...
-2
votes
2
answers
109
views
i am not able to print sum of two columns from a live stream of data using awk
so i am trying to monitor how much bandwidth get used by transmission while torrenting. I searched and find an utility nethogs.if i run
sudo netogs -t | grep transmission-gtk
i get
transmission-gtk/...
0
votes
2
answers
149
views
How to append line which matches pattern to previous line
Attempting to format tcpdump.txt file:
Lines containing date, interface, protocol, etc.
Lines containing network source device.port, destination device.port, flags, etc.
Extra lines (discard)
Input:
...
1
vote
1
answer
271
views
Linux awk script commands
I'm working on a project to extract network info from tcpdump that requires many awk pipe commands for formatting prior to import into a database used for reporting, i.e.,:
tcpdump -tttt -vi any -c ...
2
votes
2
answers
261
views
How to extract IP address and port from column in csv file using awk?
My goal is to use awk to parse tcpdump cvs file to extract network tracking and reporting information from columns #22 and #23 (columns and sample data) below:
1,2,3,4,5,6,,....,,22,23,,...
20-09-24,...
1
vote
1
answer
72
views
Print more than one column of `lsof' output while sorting and counting uniq values using one of those columns
I want to print only chosen columns of lsof output
$1,$2,$3,$5,$8,$10
and use uniq -c on the PID column while printing all of the initial columns of output.
I am on macOS. I am using awk, sort, uniq ...
0
votes
0
answers
60
views
Search a pattern from one file and replace next line with another pattern in another file in Shell script
I have two files file test.txt and ref.txt. I want to read ref.txt which has comma seperated 3 values. I want to match pattern in test.txt with first value in ref.txt, if found replace next line if ...
0
votes
2
answers
209
views
bash + how to insert date before line
lets say I want to pipe the date output in the beggining of some text
for example
echo "this line is test line" | date
and expected output should be
Wed May 22 14:55:10 UTC 2024 this line ...