Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
29 views

unix shell script : Merging data(lines) of 2 different text files

files have many entries but for sample posting only 2 entries each. I want to merge file1 first line content with file 2's 1st line content and so on.example is as below. file1.txt Start Date: 2019-...
0
votes
1answer
19 views

How to print the version of a specific MediaWiki installation to terminal

I have a LAMP environment with /var/www/html/x which is a MediaWiki website. I have a few more MediaWiki websites but I'd like to print the version of the x one to terminal. I need to do so I could ...
0
votes
1answer
40 views

How to print one line below the matching RegEx in AWK or SED

I have a file containing several switches and the boot variables. lax1-sw0101#show boot --------------------------- Switch 1 --------------------------- Current Boot Variables: BOOT variable does ...
-1
votes
0answers
20 views

using unix command, how to add column which as same name for example add salary which as same name? [duplicate]

name salary pooja 1000 yashu 2000 gagan 3000 pooja 2000 yash 3000 pooja 2000 yashu 2000 Answer should be pooja [sum of all salary], yashu [sum of all salary]... conti
-1
votes
1answer
22 views

how to capture details from nc

by the following command we can identify which ip are using port 2181 and the relevant port echo stat | nc localhost 2181 Zookeeper version: 3.4.6-91--1, built on 01/04/2018 10:34 GMT Clients: /182....
4
votes
3answers
194 views

Extract multiple lines if match

I have a command that outputs information about all DIMM slots in blocks like the following: ID SIZE TYPE 44 105 SMB_TYPE_MEMDEVICE (type 17) (memory device) Manufacturer: NO DIMM Serial ...
0
votes
2answers
24 views

awk + how to export value in awk

I use the following awk line in order to capture the remote machine that using the port 2181 netstat -nape | awk '{if ($4 == "43.64.56.36:2181") print $4, $5 ,$6 ,$9;}' 43.64.56.36:2181 43.64.56.60:...
2
votes
3answers
111 views

AWK how to count sum

input file (FileInput.txt): 10 20 3 100 5 3 27 this is my awk script: BEGIN{ while((getline line < "FileInput.txt") > 0) { } how can i count sum? I tried sum+=line however it sums only the ...
4
votes
4answers
216 views

Make awk produce error on non-numeric

I have a program that sums a column in a file: awk -v col=2 '{sum+=$col}END{print sum}' input-file However, it has a problem: If you give it a file that doesn't have numeric data, (or if one number ...
0
votes
2answers
48 views

Extract and rearrange from file

I have file which I want to extract and rearrange certain data , Old file contains a raw data this file is Input reference:cve,2017-8962 sid:45885 reference:cve,2016-10033 reference:cve,2016-10034 ...
0
votes
4answers
41 views

How can I remove repeated lines taking into consideration the text from just a column?

I have the following file: ICR1 + ICR1+1+3199 + ICR1+2526+2828 + IRT1 + IRT1+1+1489 + IRT1+713+937 + LSR1 - LSR1+1+1175 - LSR1+366+638 - NME1 + NME1+1+340 + NME1+2+118 + PWR1 - PWR1+1+941 - PWR1+724+...
-2
votes
1answer
82 views

How does this awk script to delete blank and duplicate lines work?

This awk command is used to delete blank and duplicate lines: sort abc.log | awk 'LAST != $0 {print} {LAST=$0}' I'd like to know how "LAST != $0" and "{LAST=$0}" are used and what do they do?
0
votes
3answers
50 views

How to match for an empty string in a grep pattern search?

I have a set of files containing boot variables from several cisco switches in the network. I have an requirement to filter only the switches with the boot variable empty on the next reload and print ...
-3
votes
0answers
31 views

need to change the date format of various columns in a file [on hold]

Looking for standardizing the date format in CSV comma delimited file for various date fields in file. the date field formats are not same but the standard format should be %Y-%m-%d %r.
0
votes
0answers
14 views

How to create separate files based on first column value? [duplicate]

It is tab separated 3 column file. I need to create separate files based on first column value Input: 194501 CAD 1.47421052631579 194517 CAD 1.39578947368421 194520 CAD 0.949473684210526 194501 ...
0
votes
2answers
53 views

Having nothing on stdout when executing awk script [on hold]

I run a awk script. But, it is here. This is the command awk -f awk_scr ERR.txt. BEGIN { FS=" " target="missing" } { for (i=1; i <= NR; i++) { for(j=1; j <= NF; j++) { if ($j == target) ...
0
votes
2answers
32 views

Find all lines containing only the same character and replace with the same amount of another character

My goal is to convert a NEWS format (the output of appstream-util appdata-to-news) to a markdown format (to use on GitHub/GitLab). A good approximation for me would be to just go from this: Version ...
-2
votes
0answers
27 views

Awk script code So i can easily understand logic of my problem [closed]

How to pass command line argument as filename in awk script?
2
votes
2answers
57 views

Having trouble parsing a csv file from the commandline

I have a CSV file that I've been working on for most of the day and I'm not having any luck getting it parsed properly using a Regex with awk. awk is not processing the Regex as expected. Here are ...
1
vote
3answers
56 views

How to remove the summary at the beginning of the “top” command in Linux?

I used top -b -n 2 | awk '{if ($9 != 0.0) print $0,sed -n '8,20p'}'>>text.txt , then the output is : top - 16:24:42 up 3:49, 3 users, load average: 0.23, 0.29, 0.31 Threads: 503 total, 2 ...
2
votes
2answers
31 views

CSV to html with dynamic color coding

I have written the shell script below to convert csv to HTML with color coding for a single file and it's working properly. The condition for color coding is different for different reports (csv files)...
-2
votes
0answers
44 views

Calculate percentage from two date/time stamps bash

I have two files "DURATION.txt" and "ABCDURATION.txt" which contain ~900 records where DURATION.txt is the total runtime and "ABCDURATION.txt" is a portion of that total. What I need to do is ...
0
votes
0answers
48 views

Remove Partial Duplicates in Shell Scripting

831177 830372 831177 830373 831178 831177 831178 831177 830373 830372 831958 827391 832226 824442 834434 833887 I've first line combination in 4th line and 2nd line also in 4th line I want the ...
0
votes
3answers
52 views

awk + count strings in file

we have huge file like this this is partial list in the file Topic: Ho_HTR_bvt Partition: 31 Leader: 1007 Replicas: 1007,1008,1009 Isr: 1009,1007,1008 Topic: Ho_HTR_bvt Partition:...
0
votes
2answers
47 views

awk how to sort within a row from left to right within row?

I have a project I am using awk to try to resolve. I'm new to awk and still learning. I know you can write functions in awk but I'm not exaxtly sure how to do it. I have a large datafile with xml type ...
2
votes
1answer
30 views

use “$n” as a string bash variable in an awk script?

I have an awk script in a bash script that I am starting to generalise. I would like to put the string "$3" into a bash variable and use that variable in the awk script. This would allow me to easily ...
2
votes
3answers
59 views

Awk: Count occurrences of a string in one column, between a range of lines starting 2 lines below pattern 1 and ending with a condition

I have an input file with several thousand lines. I am interested in one section of it, which contains the first instance of pattern /m.o./ in the file. I need to search for this pattern, run my code, ...
1
vote
1answer
18 views

cycle through reverse search in a custom command history file in bash

I added a line to ~/.bashrc file which appends all issued commands to ~/.bash_eternal_history file in a date directory history-number command format, such as: 2019-01-08.23:59:32 /home/sport/...
1
vote
4answers
141 views

Awk to print lines in file with multiple delimiters

I have a file that looks like: chr1 1197592 . C A . . DP=67;ECNT=1;NLOD=8.12 GT:AD:AF:F1R2 0/1:37,2:0.063:13,0 chr1 1355707 . G T . . DP=69;ECNT=1;NLOD=4.51 GT:AD:AF:...
1
vote
2answers
33 views

awk command prints first column value as 1

I am trying print column 1 and 5 if value in column 5 is available and column 1 & 2 values are equal and column 3 & 4 values are equal. For the above I am using below command. awk 'length($5)...
0
votes
3answers
29 views

using awk to modify field with condition

INPUT New,9,1 Old,11,0 OUTPUT New,09,1 Old,11,0 I would like to append to filed number 2 after first , in case if it's single digit so i would like to add 0 before the digit as the output shown. ...
4
votes
1answer
108 views

Sort multiple delimited file lexicographically by one column, numerically by another

I wish to sort the TSV file below (called min_ex) by the first column lexicographically and by the second column numerically. A X, N 2.2 A, N 5.7 A, A 5.8 A, N 2.1 A, T 0.2 B G, M 2....
0
votes
4answers
56 views

print entire line after an awk and grep

I need to search multiple patterns on the third column of a file, and then print the whole line. I am using this one below but how do I get it to print the whole line where there is a match? awk '{...
0
votes
1answer
71 views

awk is not working for my requirement [duplicate]

My requirement is that shell script should print the folder name of the file. For example comp.class is present in D:/Practice/HelloWorldPractice/bin folder, I should get output after executing ...
7
votes
3answers
397 views

Awk - replace one character only in a certain column

I have a file like this: 2018.01.02;1.5;comment 1 2018.01.04;2.75;comment 2 2018.01.07;5.25;comment 4 2018.01.09;1.25;comment 7 I want to replace all dots . in the second column with a comma , as I ...
0
votes
3answers
47 views

Extract particular string from stream

I have a file in which snort signatures are stored, I need to extract Bold ones "sid" and CVE number from that signature, here is a sample signature alert tcp $EXTERNAL_NET $HTTP_PORTS -> $HOME_NET ...
0
votes
3answers
38 views

unix awk match a string and perform delimiting

I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk. ...
1
vote
3answers
50 views

Extracting a single line containing the highest value in a given column from a text file from each consecutively numbered sub-group/family

Within my text file, I would like to take the line containing the highest value present in column 3, from each consecutively numbered family (i.e. family_1, family_2 etc.) from column 2 and input ...
2
votes
1answer
29 views

Awk - convert time value to decimal value

How can I use awk to convert a time value to a decimal value. I have been using this command for the other way round (-> from): awk '{printf "%d:%02d", ($1 * 60 / 60), ($1 * 60 % 60)}' <<< ...
1
vote
1answer
43 views

How is this awk command working across multiple lines?

I'm confused by a portion of the below command. awk '/<Directory \/>/,/AllowOverride None/{sub("None", "All", $0)}{print}' /etc/apache2/apache2.conf > myfile.txt The command replaces &...
4
votes
6answers
108 views

How to edit the entire file after match a grep pattern?

To simplify, I want to edit the whole file after matched pattern, example of a file: $ cat file ip=x.x.x.a mask=255.0.0.0 host=a ip=x.x.x.b mask=255.0.0.0 host=b ip=x.x.x.c mask=255.0.0.0 host=c ip=x....
-1
votes
3answers
69 views

how to find & replace a file path listed in a file

I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep ...
0
votes
0answers
21 views

Problem in divison with in awk ( gives only upto 6 decimal points ) [duplicate]

Say I have file o.txt A,B,47.367447754129 C,D,20.742171853178 E,F,31.890380392692 I want to divide 3rd column by 100 and want to see result as below A,B,.47367447754129 C,D,.20742171853178 E,F,....
1
vote
4answers
172 views

How to remove underscore character with awk

I have a file as below: This is an _PLUTO_ This is _PINEAPPLE_ This is _ORANGE_ This is _RICE_ I'm using below code to extract the output: awk '{ print "Country: " $NF }' report.txt Output: ...
1
vote
2answers
30 views

how to awk user input [duplicate]

I'm trying to match a pattern and then print out two lines after it. I'm successfully able to do it with the following code. awk '/'202404'/{c=3}c&&c--' consolelog.log > testing.txt I'm ...
3
votes
2answers
77 views

Remove even numbered lines of text file [duplicate]

I have a text file on a Linux system, and would like to remove every second line, which is "even" numbered. Example: I would like to remove the second line of the file, the fourth, sixth, eighth line, ...
2
votes
1answer
23 views

How to change data file format from Gnuplot to Tikz errorbars

I would like to change the format of Gnuplot errorbar data to LaTeX/Tikz format. For example, the Gnuplot format data is: 5 74.92725 74.7028332590511 75.1516667409489 112.5 112.55897 112....
-1
votes
1answer
41 views

find the relevant files with their checksum

We want to find all the .jar files with their chksum. find . -name "*.jar" ./lib/ant-1.8.0.jar ./lib/ant-launcher-1.8.0.jar ./lib/backport-util-concurrent-3.1.jar ./lib/classworlds-1.1-alpha-2.jar ./...
0
votes
0answers
36 views

AWK FS with CSV file [duplicate]

I have below file.CSV file, "ID","CODE","RATE","AMOUNT" "1","A","0",","1,2000.00" "2","B","12,0.5","1300.00" I am using below code with other logic but here, value for 3rd and column has comma in ...
0
votes
3answers
56 views

removing “na” from a column and collapsing the row

I would like to remove rows that have an "na" file 0.000 0.000 0.055 0.036 0.003 0.002 0.000 0.002 0.002 0.002 0.000 na na 0.000 0.000 na 0.002 0.002 0.003 output 0.000 0.000 0.055 0.036 0.003 0....