Questions tagged [awk]

awk is a special-purpose, interpreted programming language for extracting and reporting data.

Filter by
Sorted by
Tagged with
0
votes
3answers
76 views

keep header from file1 and add column from file2 to file1

I need to copy a specific column from file2 to my file1, while keeping the header from file1. File1: ##header ##header ##header A1 B1 C1 A2 B2 C2 File2: D1 E1 F1 D2 E2 F2 newfile: ##header ##header #...
-1
votes
0answers
38 views

I am getting error on while printing files using awk

I am stuck in these steps because I am constantly getting awk: line 1: syntax error at or near
0
votes
1answer
51 views

Changes in AWK on Ubuntu 20.04 LTS?

I am working with some huge astronomical databases and I just realized that awk is not working as expected. I'm downloading and cutting some .gz files, but awk restrictions are weird, let me share a ...
2
votes
1answer
116 views

How to keep original decimal numbers without rounding off

I am trying to compute the sum of the travel distance and it is computed perfectly in the text file. However, the results would be rounded off to 4 decimal places For instance, whenever I tried to add ...
1
vote
1answer
39 views

How to print awk's results with different colors for different fields?

ads2 cls create | awk -F [\"] '/^>>> cluster established .../ { strt=1 } strt!=1 { next } $1 ~ "name" { cnt++;nam[cnt]=$2 } $1 ~ "state" {stat[cnt]=$2;print -e "...
1
vote
1answer
55 views

awk - compare two files and print all columns from both files

I want to compare two files File 1: evm.TU.PTPU-T1. PF00808 evm.TU.PTP-T1 PF00498 evm.TU.PTPX-T1 PF00250 evm.TU.PAN-T1 PF00817 File 2: PF00808 CL0012 Histone CBFD_NFYB_HMF ...
0
votes
3answers
73 views

how to split a string from a column using awk

I am a noob in Linux. I have a file like this: col1 col2 col3 ID1234567-DNA_A01 chr1_10203040_T/C gene 0 ID1234568-DNA_A02 chr1_10203050_T/A gene 0 ...
0
votes
1answer
64 views

Extract frequency value from last column depending on what letter is there to plot

I have a tab-delimited file that has frequency values in the last column (actually the values are tab-delimited as well). I have mostly two values (e.g., A:0 G:1) but some rows have three values (e.g....
0
votes
0answers
141 views

awk print question

Can you please explain what this code does? I know 'awk NR==2{print $4} means the 2nd line 4th field of the ${x}_${y}.dat file. T=`awk 'NR==2 {print $4*100}' ${x}_${y}.dat`
0
votes
0answers
19 views

I want to search with RETCODE & find 5 lines above beginning with NE : . Is there any way to do it with grep?

**NE : TALS1_TO** Report : +++ TALS1_TO 2021-01-25 02:02:18 O&M #806356831 %%/*1884960535 MML Session=1611550934*/MOD CELL:LOCALCELLID=2,CELLNAME="QALS12",ULEARFCNCFGIND=...
5
votes
2answers
378 views

awk if find pattern skip n lines

How to skip N lines when a pattern is found in awk? awk '{if ($0~/pattern/) skip N lines; else print $0}'
0
votes
0answers
27 views

what NF stands for in awk?

I know NF is the last element, as explained here: NF is a predefined variable whose value is the number of fields in the current record. awk automatically updates the value of NF each time it reads a ...
1
vote
1answer
48 views

Why GSUB does not work in AWK?

I am trying to do a substitution with AWK by passing two variables that are going to be used in the substitution. My initial try was: FILE=a cat $FILE | awk -v var1="$Linea_SF" -v var2="...
0
votes
1answer
60 views

awk -v var=$var /var/ is not working as expected

Portion of file: <style:style style:name="P15" style:family="paragraph" style:parent-style-name="Table_20_Contents"> <style:paragraph-properties fo:text-...
1
vote
1answer
59 views

Pass a variable in awk command

spke="myvaribale" var="cidr" val=$azure_spoke2_vnet_cidr clp="azure_vnets" I am placing these variable in this command : I dont want to write this myvaribale in ...
1
vote
1answer
219 views

merge partial duplicate rows in a table

Input is a settings file with multiple rows separated by tab. h1 h2 h3 x y h4 h5 h6 h7 a b c h4 true a b c h5 false a b d h4 false m n o h6 true m n o h7 false p q r h4 true ...
0
votes
1answer
45 views

awk parameter substitution fails

I am on Ubuntu 20.04 Mate Desktop environment. I encounter a strange failure when I attempt to pass the date string to regex query in the following line : date="2020-12-11" cat /var/log/...
0
votes
4answers
160 views

Awk/Sed commands find and replace pattern

I have a file with data like the following. xyz can be anything, so I want to replace it. variable "azure_spoke_gateways" { default = { spoke1 = { name = "xyz" ...
0
votes
1answer
55 views

awk remove duplicate words

I want to extract installed packages in a specific date to remove them easily. I can list them in a line with the following command: cat /var/log/dpkg.log | awk '/ installed / && /2020-11-23 ...
0
votes
1answer
46 views

AWK to compare columns in file1 to file2

I have a simple problem but have not been able to solve. I want to compare columns 2, 3, 4, 5 and 6 of File1 to the same columns of File2 and if they match then add Column1 of File2 to Column7 of ...
0
votes
1answer
20 views

Sed insists on doing partial matches

Ok, consider this example file: #!/usr/bin/env bash cat > example_file.txt <<EOL group, , price 1, S_BRN_, 3.21 1, S_WBS_BRN_, 4.11 1, S_WBS_BRN, 1.22 2, S_BRN_WBS, 9.2 2, F_WBS_BRN_, 2.11 2, ...
1
vote
2answers
81 views

awk condition is not working properly

These are the data on which I am applying an awk command: ~$ cat lab4.data Mike Harrington: (510) 548-1278:250:100:175 Christian Dobbins: (408) 538-2358:155:90:201 Susan Dalsass: (206) 654-6279:250:60:...
0
votes
1answer
24 views

How to use awk to edit a specifc line set by a variable (awk NR, -i inplace and -v var)

If file is: this is line one this is line two this is line three I want to do something like: awk -i inplace -v line_number=$line_number 'NR == line_number {print $1}' file Lets say line_number=1. ...
0
votes
2answers
54 views

Remove LF from a specific column using sed

I have a file which contains data separated by |. Example: (Input) a|b|c|d`LF` D|e a1|b1|c1|d1`LF` d2|e1\n Output: (Removed LF from 4th column) a|b|c|dD|e a1|b1|c1|d1d2|e1\n I want to remove LF from ...
0
votes
1answer
22 views

Define fields by content and remove separator inside

I have some comma separated files that unfortunately contain commas inside some of the strings. That makes sorting them non trivial. See previous question. Regardless of the sorting, I figure it would ...
0
votes
1answer
58 views

How to replace every 2nd line sed

How to replace every 2nd line of a text file with another text file list of lines. Example: cat filea.txt I love Pink I love Blue I love Dogs I love MOMO cat bileb.txt I hate yello I hate white I ...
0
votes
1answer
28 views

Editing wc -l src Output

I am new to the Topic and working on a few bash commands. I am stuck at a task where i Need t ouput my result in a specific Format. wc -l folder/* The Output gives me: 0 folder/file1 3 folder/file2 3 ...
1
vote
1answer
793 views

Convert HTML to text format

I want to extract the page content from this HTML file: <BR /> <TABLE style=border-color:#32506d border=1 cellspacing=0> <caption class=header style=background-color:#32506d><...
0
votes
1answer
98 views

awk NR variable not working as expected, getting the whole line while asking for first field

echo cat: cat Records.txt echo "" echo Using a digit for the second record: record_id=$(awk 'NR==2{print $1; exit}' Records.txt) echo $record_id echo "" a=2 echo a is set to $a ...
1
vote
1answer
51 views

Using awk for a bash script that defines a “minimum packages set”

I would like to write a script with the following requirements: in input, get a list of packages available via apt. In there you may have some packages that are automatically installed by other ...
0
votes
1answer
56 views

Change the text according to match for each line

I have a text file which contains some text is shown below: I love bash $ I love html $ I hate you I love you man I want to add some text at the beginning and the end of the line with a match of $. ...
0
votes
1answer
460 views

how to pass string comand to shell pipe to execute it (output of awk)

For example this works: echo 1 // output: 1 This doesn't work: 'echo 1' | "/bin/sh" // output: echo 1: command not found Why string because i have output of awk and i need to pass the ...
0
votes
2answers
57 views

AWK with RS not matching a pattern (asking again becuase I accidently labled as solved. Better explanation ths time.)

I have an odt file with blank lines between lines of text. I want to search for a term and output the whole group of text where there is a match to the term. My approach is to say that the blank lines ...
0
votes
1answer
247 views

Combine two files and aggregate another column

I'm trying to compare two files, on basis of the id column, A.txt contains ID, NAME fields. B.csv contains ID, NAME, PLACE, DATE, I want find which month had most of the ID's from a.txt I'm trying to ...
0
votes
0answers
64 views

AWK with RS not matching a patten

I am trying to extract a "paragraph" from an file. There are not blank lines between paragraphs, but there are lines that do not have text between > <. My approach is to designate RS ...
0
votes
1answer
47 views

Parse Xauthority file

How can I parse the Xauthority file in Ubuntu. I tried something like this: cat /run/user/1000/gdm/Xauthority | awk -F'-' '{ print $2 }' According to the format, the first value should be user and the ...
3
votes
0answers
89 views

Is there any online awk command “explainer”?

First, I am not sure where I should ask this question. Please point me out the correct forum if this place is not meant for this. I am looking for a tool that can explain awk commands. As a reference, ...
0
votes
1answer
43 views

AWK: How to delete last pattern?

I have a path: /home/alejo/Desktop/Proyecto_UIS-MINCIENCIAS/qmmm_propranolol_aescorcia/A_PSF-NUEVO/ORIII/MCC/out/mcc_oriii_after_centering.pdb I want to have: /home/alejo/Desktop/Proyecto_UIS-...
0
votes
0answers
68 views

AWK does not sum decimals

I have a file, z: .57 .57 .57 .57 I type: awk '{sum+=$1}END{print sum}' z and I get 0. I have a file, zz: 1 2 3 4 I type: awk '{sum+=$1}END{print sum}' zz and I get 10. Why those sums are different?
0
votes
1answer
139 views

Copy and paste between special lines using awk command

I have a problem with awk in this command awk 'NR==1,/mode/{next}/tot/,NR==0{next}{print}' 1.out > 2.dat From the contents of file 1, I put the lines between the line that starts with the word ...
1
vote
2answers
77 views

How do I get `abc.xyz.com` from `“127.0.0.1,abc.xyz.com”`?

I have a list in which data is in this format "127.0.0.1,abc.xyz.com" I want to get only abc.xyz.com without the IP address and double qoutes. How it can be done?
1
vote
1answer
48 views

Compare two columns from two different files and display output in new file

file1.txt psid task status 1 a1 run 2 a2 run 3 a3 stop 4 a4 run 5 a5 stop file2.txt a1 stop a2 stop a3 run a4 run ...
1
vote
1answer
1k views

How to search an XML file and print text of a certain color

I have tried grep, awk, sed and am starting to try xmlstarlet but I'm not finding much support with that. I'm guessing the xmlstarlet is telling me that the XML is ill formed, but all I want to do is ...
0
votes
0answers
172 views

how to make awk extract text in xml with a tag that includes quotation marks

Without quotes, it works fine. If the line in cust.xml is : \<span style=CustomerId/>999\</CustomerId> <br> $ awk -F "[><]" '/span style=CustomerId/{print $3}' cust....
1
vote
1answer
54 views

Print selected columns from a file if the row is mentioned in another file

My first file contains data like: Gene symbol Gene name Chromosome Start End Strand Otter gene ID Otter transcript ID Ensembl gene ID Ensembl transcript ID Gene biotype Transcript biotype ...
1
vote
1answer
3k views

Cannot kill container: foo: Container foo is not running

Perhaps kill is incorrect terminology, or I'm at least using it incorrectly. How do I destroy docker containers? Put them in the trash. Delete. Remove. Erase. docker container kill $(docker ps -a -...
1
vote
1answer
72 views

Get human readable cpu frequency

I am trying to get a simplified output of the cpu frequency to 3 digits, such that if the frequency is less than 1000 it will output xxx Mhz and if it's above 1000 it will outpute x.xx Ghz. I can get ...
0
votes
1answer
90 views

How to replace a string found by awk

I have a nginx file and this block specifically, upstream jira.example.com { ## Can be connected with "nginx-proxy" network server 172.21.0.5:80; Basically I want to replace ipaddress and ...
1
vote
0answers
22 views

Cron Execution Issue

First off, I have searched past crontab related postings without finding any pointer to what the problem I'm having might be, so apologies if this has already been covered. Also, sorry if the ...
1
vote
1answer
24 views

Modifying the numerical values with awk in a file , following a matching pattern only

I need to multiply the numerical values with a constant say 0.9 for numbers following a pattern "-period". Only the numbers after the pattern "-period" need to be multiplied but ...

1
2 3 4 5
10