Questions tagged [awk]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
39 views

Why can't I get this code to work? $ echo mean? “”>>/apache/conf/httpd.conf [closed]

When I created the configuration file apache/conf/httpd.conf and went to check if it was in the system the program was saying that the file does not exist so how do I recreate the file so that it does ...
3
votes
2answers
43 views

How to sum the values in multiple text files?

In Ubuntu desktop 20.04, I have 20 directories, each containing a text file with the same name, "weights". These text files contain ~20-30 numbers separated with a space. In each of the 20 directories,...
1
vote
1answer
54 views

How to add n columns below first column? [closed]

I have a tab-separated data: 1-1 2-1 3-1 ... 1-2 2-2 3-2 ... 1-3 2-3 3-3 ... 1-4 3-4 ... 3-5 My desired output should look like this: 1-1 1-2 1-3 1-4 2-1 2-2 2-3 3-1 3-2 3-3 3-4 3-5 ... ...
0
votes
1answer
32 views

How to get user input in awk script

I'm writing an awk script that calculates some statistics. First I need to get an user input, which is a string, and store it in a variable (center). I have this: #!/usr/bin/awk -f printf "Enter the ...
2
votes
0answers
22 views

using awk to find special charecters in txt file

I need to scan a file with many different special charecters and values. Given a set of special charecters - I need to provide the value next to it: 547 %$ 236 \" 4523 &* 8876 (* 8756 "/ ... I ...
0
votes
2answers
81 views

How to do a simple mathematical operation on all lines of a specific column?

I have a text file named nvt.gro. I want to add 0.5 (+0.5) on all the lines of the last column: my file is as below: GRM in vacuum 192700 1GRM C1 1 17.188 0.311 13.994 -0.5971 0.0204 -...
2
votes
4answers
142 views

How to align the text file after copy and paste?

I copied column 7,8 and 9 from file 1 into columns 7,8 and 9 in file 2 producing a new file 3. the produced file (file 3) is not aligned as the original files, How can I edit it to preserve the ...
0
votes
1answer
45 views

How to print the first word of a string in a specific column using awk

I have this output using cat csvfile: Center_code Name City_code 800 SCHOOL NUMBER ONE 8000 801 SCHOOL NUMBER TWO 8010 802 ...
1
vote
1answer
118 views

Filtering the lines which are greater than a percentage value

Hello i need to filter lines which are greater and equal than 85%. I need to filter according to Forward: Score line and end of the percentage of that line. Example file: Scores for this hit: >...
1
vote
1answer
27 views

awk gsub question

I've used awk in the past for large file manipulation and substitutions.Recently, I've used it to substitute, for ex letter A with a set of characters: $ awk '{gsub(/A/,"@@@")}1' in.txt >> out....
0
votes
2answers
40 views

How to arrange every n rows into columns using awk

I have a tab-separated data like this: a 2 b 3 c 4 d 6 e 8 f 9 g 10 h 11 i 12 ... My desired output should look like this: a 2 d 6 g 10 b 3 e 8 h 11 c 4 f 9 i 12 How can I do this, for instance ...
0
votes
2answers
32 views

replacing the particular line in bash

I wanted to change 800 line in one file say test.txt if i use the below command it works sed -i '800s/old_pattern/new_pattern/' $filepath Is there a way to pass the line number through variable ...
0
votes
1answer
34 views

Grep from nginx server files, but exclude www.domain.tld

I have a command in a bash script like this, to get me an array of all the domains on my webserver. domains=($(grep -rnw '/etc/nginx/sites-available/' -e 'server_name' -l | xargs grep -e 'server_name'...
-1
votes
1answer
197 views

Install gawk-csv (or gawkextlib) with apt

There are a way to install the CSV extension for gawk by apt? The name of the main lib is gawkextlib. It is a very important extension for classic AWK, because generic CSV file is not only "a,b,c",...
0
votes
1answer
50 views

How to separate 2 variables in awk print with echo?

I did a small test to echo everything in my .txt named portal. When writing in terminal I want the script to echo all with the name entered but I only show the first variable. input=$1 for portal ...
0
votes
0answers
16 views

Insert string in a specific column based on whether it is present in a file

I have a script that scans for wifi access points and lists them in the following way in file1.txt: wifi1 wifi2 wifi3 wifi4 and the same script on each scan reads the signal quality of each wifi AP ...
-1
votes
2answers
52 views

How to combine TSV file

I have four TSV files like this: file_1: abc \t 1 def \t 3 ghi \t 5 file_2: abc \t 10 def \t 4 ghi \t 7 file_3: abc \t 8 def \t 5 ghi \t 1 file_4: abc \t 4 def \t 2 ghi \t 1 I want to combine ...
1
vote
1answer
52 views

How to filter data with the highest number

I have thousands data like this: abc_1 abc_2 abc_3 abc_4 def_1 def_2 def_3 ghi_1 ghi_2 I want to filter it to get only data with the highest number which is abc_4, def_3, ghi_2. How I can get it?
1
vote
1answer
72 views

Using AWK, how to use tabs instead of Space as field seperator?

I have the following fields: Name<tab>City<tab>Phone Number If I use to awk, it returns only first name ("Muhammad"), when name is "Muhammad Tahir". How can I use awk with grep so it ...
0
votes
2answers
139 views

Find match in csv file

I have two CSV files. 1.csv contains: 46700468915;2000 2.csv contains: 4670046;Tele2 I am trying to searching from 2.csv if 4670046 exists in 1.csv which is does and then take from 2.csv Tele2 ...
0
votes
1answer
20 views

why is my output not correct while dividing by a variable in awk?

I wrote a little watch script to watch the load avarage on a Linux server (just for learning purposes and because watch uptime isn't giving the output I want). It works great, but to have the load ...
0
votes
0answers
34 views

Rounding up to two decimals using awk in shell script

I have prepared a shell script in that by division of two numbers. I am getting output as 0.56666666 but the output need to be restricted as 0.56. Below is the code I have used. percent[j]=$(( (${...
-1
votes
1answer
80 views

I need help with this awk script

The following data contains a variable number of fields per record with each row being a single record. Awk script that will add all of the fields for each row together and print the resulting sum per ...
-1
votes
1answer
53 views

Sed, extract lines from text

I really would like to know how can I extrac some line from a text file using sed, but I'd like to extract the lines at interval: For example extract the line with number i=1:2:100 So that i can ...
1
vote
1answer
570 views

Bash script to split file by its content renaming the split files from an another file

So far I was only reading, but now I have to start with a complicated question. I was googling crazy but I can't find an answer and it must be in BASH. (Thank you for the ideas like Perl, not an ...
0
votes
0answers
44 views

removing decimals using awk

I have a CSV file where I want to remove the everything after . My input file looks like this: ENST00000456328.2,ENSG00000223972.5 I have tried using awk -F\. '{print $1"\t"$2}{next;}' I want an ...
1
vote
1answer
110 views

how to trim few words in 2nd column to display in a text file

Original: 'abc','X:1234','cde', 'YYY', 'XYZ' 'abc','X:2345'','cde', 'YYY', 'XYZ' Want to outcome with the below, in which 2nd column trim to 4 characters, before is 6 charaters. 'abc','X:12','cde',...
0
votes
2answers
98 views

How to calculate average of 2nd field from files?

I have a file and it consists of two fields. The first field format is "%FT%T". Sample data: 2019-01-01T00:00:00 4.8 2019-01-01T01:00:00 5.1 2019-01-01T02:00:00 5.4 2019-01-01T03:00:00 5.7 2019-...
-1
votes
1answer
63 views

Replace XML tags by numbers

Suppose i have an xml like this <a> hey how are </a> <a> where are you </a> I want to change them and assign number like this-- 1.hey how are 2.where ...
1
vote
1answer
257 views

How do I get values from string and then convert these values to different time zone?

Data format as follows: 2019 12 18 18 15 05 TIMESTAMP 2019 12 18 23 15 05 TIMESTAMP These values in strings are respectively year, month, day, hour, minute, and second. I try to write awk ...
1
vote
2answers
140 views

How to manipulate specific fields?

I have a csv file. Its line numbers are max 25. Headings are time(UTC)(1st field), latitude(2nd field), longitude(3rd field), depth (4th field), mag(5th field), place (14th field) and so forth ...
3
votes
2answers
170 views

How to insert filename by changing format to same file?

I have many files. File format is year(4-digit)month(2-digit)day(2-digit) Sample filenames: 20150101.txt 20150102.txt Content of sample filenames 00:00:13 -> 001528 I want to extract data as ...
7
votes
4answers
562 views

How would you separate fields with multiple spaces and store them in an array?

In my file mytxt: field1 field2 ------ ------- this are numbers 12345 this letters abc def ghi Let's say I want to store the first field ...
1
vote
1answer
62 views

How to add new columns to CSVs with the same text in all lines

This a sample of my input file: 22/12/1999,conductivity,42,uS/cm 06/01/2000,conductivity,22,uS/cm 26/01/2000,conductivity,26,uS/cm 09/02/2000,conductivity,32,uS/cm 23/02/2000,conductivity,33,uS/cm I ...
2
votes
1answer
64 views

How do I get words of certain length?

Supppose I have data like this: this is ttttaaaaa aaattt The expected output that I am looking for is: is ttttaaaaa I am using awk. This is the idea: awk 'length <= 4 && length >= ...
1
vote
2answers
252 views

how to find or list file and directories which having size more than 100mb

How to find or list file directories which having size more than 100 MB I'm using du -sh* to get the size of file but my system don't have permission
3
votes
2answers
80 views

Getting lines between special char pattern

Below is my input file: --- { "date":"2015-09-24", "title":"Getting Started with Git", "template":"post", "thumbnail":"content/thumbnails/test.jpeg", "slug":"getting-started-with-git", "...
0
votes
1answer
1k views

Add or append new column to csv file using shell script

I have a CSV file it includes some columns, in that I have the start time and end time. My requirement is to get the difference between the time and add the difference to a new column. I'm getting ...
0
votes
1answer
134 views

How to rearrange text file via awk?

I wanna print field (from 4th to the last field) as new line for each by inserting increasing arithmetically variable (from 5 to 25) after 3rd field in the text file. Data format: 01.01.1995 01:00 1....
1
vote
1answer
534 views

command line autocomplete does not work in ubuntu 19.10

when trying to access the autocompletion in ubuntu 19.10 it always throw an error: awk: line 18: function gensub never defined I think there are some system libs have wrong version or linked to ...
0
votes
2answers
104 views

How to convert gjf format to xyz format?

The gjf format is as follows: %chk=test.chk # hf/3-21g geom=connectivity Title Card Required 0 1 C 0.53424883 1.46721985 -0.02620215 H 0.89090326 0....
1
vote
3answers
170 views

how to grep two paragraph from file?

i have file "test_file.txt". My output must contains all"IP ADDRESS" and "MONTHS OF 2017" from file test_file.txt. Server$ Server$cat test_file.txt IP ADDRESS: 1. 172.17.17.17 2. 172.17.17.18 3. ...
0
votes
1answer
31 views

grep a word/number between two specific characters

When you ping you will get the ip between () , for e.g : (10.10.10.10) and after the ip there are (number) for e.g : (10.10.10.10) 56(84) so how i can get the ip that is between the () ? and without ...
0
votes
1answer
51 views

I need to pull email size for each email in a sendmail log, then total them up with the total size and total number of emails

The size is simple to find after size= i can find the size and put it to a file but removing everything but the numbers and then summing it with the total numbers all in one file is just not coming ...
0
votes
0answers
45 views

extract specific strings from a file [duplicate]

Using cat index.html | grep 'src.*js' I got these results: <script src="/c/dam/cdc/j/adrum.js"></script> <script type="text/javascript" src="/c/dam/cdc/j/targeter-bundle_min.js"><...
7
votes
1answer
288 views

How can organize the disordered columns using awk/sed?

I have 2 columns including some data like: one two one two one two How can we convert it to: one two one two one two
6
votes
4answers
563 views

Count number of different name in a file

I want to count the number of different name in a text file of this presentation: 2008 girl Avah 2009 girl Avah 2008 girl Carleigh 2011 girl Kenley 2012 boy Joseph 2013 boy Joseph 2014 boy Isaac 2014 ...
3
votes
1answer
94 views

Add specific text/tag after every few lines in bash

I have a text file where I have to add tags (in the form of normal text) to a .txt file. For example, suppose I have a text file like this: a b c d e f g h I want to add the tags <hello> and &...
0
votes
2answers
108 views

Compare 2 cols; when 1st col > 2nd col, remove 2nd col

How can I compare 2 cols in csv file, divided by ,, and cols contains quotes " when , is present in generated col, and when 2nd col > 1st col, then remove 2nd (last) col. I did something similar, ...
2
votes
1answer
66 views

Remove words from a column in a file

I have file which contains something like below 5,test,2019-09-27T11:06:23Z,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2 4,test,2019-09-26T16:56:40Z,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1 ...

1
2 3 4 5
9