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 [awk]

A pattern-directed scanning and processing language.

0
votes
3answers
18 views

Can I grep/awk/sed a line for multiple matches in a single line and get the info after it?

I get files that come in from an external source that are unordered... and contain bits of info I'm interested in and some that I'm not. name: myName var1: xxx var2: bbbb var1: xxx var2: aaaa name: ...
1
vote
0answers
24 views

awk print tab delimited columns with find execdir

I am trying to print out columns that are separated by tabs. First, I use find command to identify a list of files to process. Second, I parse the file path to generate the filename to be used for ...
2
votes
3answers
35 views

Remove all matches containing a string until its next space

I want to delete all matches in a text following this pattern: Each match starts with linux- Each match ends with a space (Remove linux-* until immediate next space) EXAMPLE: From this text: ...
0
votes
1answer
27 views

awk + how to capture the third field on both characters

from ps ax we get the following output ps ax PID TTY STAT TIME COMMAND 1 ? Rs 611:56 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 2 ? S ...
3
votes
2answers
157 views

How to obtain only positive value in second column [on hold]

I use this command awk 'NR%2{t=$1;next}{print $1-t,$2}' to get the distance between two consecutive Y points in a file. But I would like to have all positive numbers. How to get that ? like ...
0
votes
0answers
25 views

How to calculate the wavelength of a oscillating data [on hold]

I have a data that generates a oscillating diagram. [ Now I would like to calculate the wavelength of this data? i.e. the distance between each crests of the oscillating figure. What is the best ...
0
votes
0answers
35 views

Printing one column from one file - awk

I have this program that restrict the area in input file where is a table and print the number from it. Some of them after an arithmeric operation. I use this program for several files. BEGIN { ...
0
votes
1answer
24 views

How to run shell command inside awk and redirect to another shell command?

I want to get particular string from the files downloaded using curl and redirect the downloaded file content to another shell program. Here is the code : curl "http://file-list-url" -s | awk 'BEGIN {...
0
votes
1answer
61 views

Run bash command from awk system only once

I am using tail -F to monitor a severe weather alert server log file and awk to filter and execute a command if the conditions for an alert are met. I need to execute the bash command(an ssh command ...
2
votes
4answers
52 views

BUILD LOGIC - what could be better than using AWK?

Below is how a log looks like: Company=XYZ Req_id=1234 Time_taken=10 sec Status=Success Company=ABC Req_id=3456 Time_taken=200 sec Status=Failure Company=DFG Req_id=3001 Time_taken=15 sec Status=...
-1
votes
0answers
28 views

awk text processing for multiple pattern pairs

This is a repost of my previous query which was well answered by Gerard, search pattern pair using awk Now I have another addition to this query, So here is my query. Below is input string: Policy ...
2
votes
1answer
31 views

redirect awk exec results to another folder [duplicate]

Trying to capitalize the content of the files that match the filename pattern "_base.txt"; then output the results to another folder with the original filename plus the "_cap.txt" in the end. I plan ...
0
votes
2answers
21 views

Finding exact string from variable in an awk commmand?

I'm trying to the use the following awk command to return a user from a file that lists all users on the system but only if the 8th field is empty and they match the user variable (it's being using in ...
0
votes
4answers
72 views

Need identical lines from file2 which are present in file1

File1 contains numbers each per line (0 to 9 digit length) total records 20k File2 contains numbers(0 to 9 digit) in first column and other info in each line,total recs 46 ,000,00 Both files are ...
-1
votes
0answers
47 views

How to get department wise total from text file

I have a text file as below: sales|100 accounts|500 marketing|200 sales|50 sales|70 accounts|300 marketing|40 accounts|150 marketing|200 sales|80 with the following script, I have generated ...
9
votes
4answers
537 views

awk assign to multiple variables at once

I'm trying to pull two numerical values out of a string and assign them to variables using awk (gawk is what I'm using specifically). I want to pull the major and minor version numbers out of a tmux ...
1
vote
1answer
25 views

Determine Missing DIMM

When a memory module in one of my servers fails the event log will often report the wrong DIMM slot or a non existent DIMM slot altogether. The best way we have come up with to determine the failed ...
4
votes
2answers
242 views

GNU awk ERRNO not set on command failure

I was trying run a few commands using getline() function of GNU awk and print the error number (errno) value returned. But for simple failure cases of non existent directory/file the variable doesn't ...
0
votes
0answers
17 views

convert my csv file output to html table with heading bold and and send email using post fix & also want to change the font to calibri

for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{print $2","$5}' ; ssh Reports@$i showpd -degraded -failed | awk '{print $1","$2","$3","$5}' ; done | grep -v "MiB" | grep -v "total" | ...
-1
votes
2answers
47 views

filtering output

for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{print $2,$5}' | column -t ; ssh Reports@$i showpd -degraded -failed | awk '{print $1,$2,$3,$5}' ; done | grep -v "MiB" | grep -v "...
0
votes
1answer
33 views

remotely executing a command using ssh

Here I'm trying to remotely execute a command on multiple devices using ssh using while loop in bash however I'm getting output for the first IP in source file but not for others. cat HPE_FRAMES_IP ...
-3
votes
1answer
22 views

awk query for sequential replace a pattern

I found the below awk command to sequentially replace a particular line in a file, but i would like to know how this works. Input:- DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 DS: 1 output:- DS: 1 DS: 2 ...
0
votes
1answer
23 views

Generating a ssh Host config file out of a Supperputty XML file

I am building a script that generates an ssh config file out of a Supperputty XML Session config file. I don't know which tool could handle it better. I try to achieve it with awk, but I don't receive ...
0
votes
1answer
27 views

single long line searching

I have a large document that is only 1 line, it spans multiple pages of vi. Below is an extract of a small bit, I'm seeking to show text after aria-label=" I would then like to stop at aria-...
1
vote
1answer
13 views

Subsetting a variable by pattern

I have a delimited file with the following format that I have assigned to a bash variable "foo": echo $foo A 1 hello B 2 hello C 3 hello D 4 world E 5 world F 6 world I am trying to ...
0
votes
1answer
43 views

Extracting rows from tabular data based on date range [closed]

I have a table with 10 columns. One of them is a date column and I want to get data for a specific date range. For example, I have data from the year 2016 and onwards, but I want to fetch data only ...
0
votes
1answer
34 views

How to find encapsulating function name from line number

I am looking at a log file which just tells me the filename and the line number inside that file that has the Error. What I am interested is knowing the encapsulating function. For example, here are ...
1
vote
1answer
15 views

Add values when X columns exist

I have a file that looks something like this InvoiceDate Bill Person BAN Type Amount Amount-Expenses GreenFee TaxAmount FinalTotal 1524753593 Jennifer Doe 39193 S ...
1
vote
4answers
51 views

Format Date fields in Pipe Delimited File

I require assistance with this I have a pipe delimited file that is formatted as such Location|1111|222222|333333|Doe|John|19900723|19900724|19900725 The last 3 fields are Date fields, but I can't ...
0
votes
3answers
35 views

How can I use AWK to break line content into multiple lines using a separator

Given an input like this: field1,field2,field3,field4 I would like to get an output like this field1 field2 field3 field4 How can I do this with awk?
1
vote
2answers
29 views

Printing the column names using the output of “df -h” (macOS)

I am trying to: Print the output of the command "df -h" (in macOS),but only with /dev/disk* as ouptut. I used the following command: df -h|awk -F"\t" '/\/[d-v]{3}\/[a-z]{4}[0-9]{1}[s-t]{1}[0-9]{1}/{...
-1
votes
0answers
25 views

How to combine multiple commands into one script (awk & sed)

I have an output file test_mini [...srv01]$ cat test_mini tobias@(Whatever_LTM1)(cfg-sync Changes Pending)(Active)(/Common)(tmos)# cd ..;list /ltm virtual recursive destination^M Display all 96 ...
5
votes
2answers
148 views

Why is `sed` no op much faster than `awk` in this case

I am trying to understand some performance issues related to sed and awk, and I did the following experiment, $ seq 100000 > test $ yes 'NR==100001{print}' | head -n 5000 > test.awk $ yes '...
1
vote
1answer
25 views

turn awk command into an awk script (multiple F)

I have a working command awk -F '[)#/(:]' 'BEGIN { fw="";dev=""} {if ($0~/sh failover/) fw=$1 ; if (($0~/This host/)||($0~/Other host/)) dev=$2; if ($0~/\)\:/) {print $2,$1,fw, dev} }' OFS="|" ...
1
vote
1answer
34 views

Why is this regex not working in awk?

I have a text file as such: Attribute 1.............. : attribute value Encode Date............................. : JUL 2007 Attribute 22076.......... : attribute value` I want to extract the JUL ...
1
vote
2answers
49 views

Compare every nth line in 2 files and save (asymmetric) context

I have 2 files, each containing the same amount of 4-lines records, in the same order: fileA: record1 line1=header record1 line2 X <= this is different but should be ignored record1 line3 id ABC ...
2
votes
0answers
53 views

Good projects for bash and awk [closed]

I am learning bash and awk programming, and have gotten to the point where I want some interesting projects to work on to improve my programming. At the minute, the beginner stuff is getting too easy, ...
0
votes
1answer
34 views

csv filter on linux bash

Problem: I have a CSV file with 5 columns (1st column is a string and the other 4 are int). I would like to filter based on the third column, Revenues, the largest on the top and smallest on the ...
0
votes
1answer
33 views

merge multiple rows based on a key column

My csv file looks like the following: 8 id1 xyz 1 id1 abcdef 2 id1 mv 1 id1 tzfl 6 id2 xyz 1 id2 abcdef 1 id2 mv 5 id3 xyz 2 id3 abcdef ... 8 id100 xyz 1 id100 abcdef 2 id100 mv 1 id100 tzfl 4 ...
1
vote
2answers
50 views

Compare data in 5th column with 6th column and print the least difference element

I have a file with below data: APPLE,FRUIT,1KG,RED,1660.00|1680.00|1700.00|1720.00|1740.00|1760.00|1800.00|1900.00|1920.00|1520.00|1320.00|1340.00|1360.00|1380.00|1400.00|1420.00|1440.00|1460.00|1480....
1
vote
1answer
25 views

How to prevent printing to stdout from an awk **script** (not from cli)

[GNU awk v4.2.1 on Archlinux] Suppressing awk's default print action to stdout from cli is easy and well documented on UL, e.g. here. Doing so from a script gives me headaches. Here's the toy script: ...
3
votes
2answers
47 views

Merge every two lines after processing each of them with external shell command

I have a file of the following structure: #1552342335 ls #1552342359 date #1552342380 cat .bash_history i.e. timestamp followed by a text line. I want to process every timestamp line using shell's ...
0
votes
1answer
24 views

Text file: find string, save string field to var, find 2nd string, replace field with var, repeat to end

I think this would best be done with AWK, but not sure. Its been stumping me all day how to do this. I have a text file with * delimiters between the fields on the lines. I need to search for lines ...
0
votes
2answers
53 views

Splitting text file into CSV with multiple delimiters in bash?

Trying to parse a text file into CSV. Catch is that I have multiple delimiters currently, that I'd ideally like to use as column headers but can strip out of the csv results. Ideally would rather ...
1
vote
1answer
27 views

awk: add column name with filename in loop

I have a question to add a column title during a loop with awk: I currently have this code, which calculates the mean of each line for each csv file : for i in *.csv; do awk -F"," 'NR==1 { next } ...
-1
votes
0answers
36 views

Grouping records with awk

I want to group records 7 by 7 and after print some fields. For example the text below: $GPGGA,132300.000,2254.5838,S,04310.9530,W,1,6,1.76,-0.8,M,-5.6,M,,*63 $GPGSA,A,3,21,13,15,29,26,05,,,,,,,1.97,...
1
vote
4answers
42 views

Get a specific words from a specific line from a text file in NetBSD

How does one proceed to extract member names from a list like the one below and output them to a new file? Group-name supernatural Members admin, Admin1, John, sam, dean Group-id 405 expected out-...
0
votes
1answer
34 views

nmap output in CSV format sorted by IP address

I have this command which works well to give me a list of IP addresses, MAC addresses, and MAC vendor, sorted by IP address. sudo nmap -sn 192.168.103.0/24 | awk '/Nmap scan report for/{printf $5;}/...
1
vote
1answer
32 views

bash: awk write each match to a file and increment filename

I want to read a file without whitespaces, filled with root certificates and seperate them into new files per match. I can select all matching certificates at once and insert to a single file, but I ...
1
vote
1answer
24 views

using conditional awk statement to control regex pattern

I have code that parses through a csv file and then checks each field against a regex. however there are a few fields that need to be mandatory if another field has data in it, so I essentially need a ...