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

learn more… | top users | synonyms

1
vote
1answer
28 views

Ubuntu bc weird behavior

There is a weird behavior in Bash script. Trying to run following lines in two different systems. Script: cpuIdle=$(mpstat 5 1 | grep Average | awk '{ print $12 }') cpuUsage=$(bc <<< "100....
0
votes
0answers
25 views

parsing and merging two different file

file 1: a 1 b 2 c 4 file 2: a 3 b 4 f 5 output: a 1 3 b 2 4 c 4 0 f 0 5 in awk if I do awk ' NR==FNR {a[$1]=$2; next} $1 in a {print $1,a[$1],$2}' file1 file 2 it will give me a 1 3 b ...
-1
votes
1answer
50 views

Reg ex - awk - grep from getline result [closed]

I have a expr in awk, but I can't grep the result echo 34100 | awk '{expr $1 / 33.7 | getline result;}' -> sh: 1: 1009.89: not found the calculation is ok but I need to have the 1009.89. Could ...
1
vote
3answers
88 views

How can I extract pdf names from an lftp log file?

I have a log like this : 2016-05-11 07:09:54 ftp://test@test.dyndns.info/test1/fool/1999/How/05%20May/test160511.pdf -> /test/keep/more/use/05/test160511.pdf 0-28442281 33.5 KiB/s i need to ...
0
votes
1answer
44 views

printing distances of desired character based on occurance

This is an extension of my previous question (Printing pattern of "C" character). I would like to print "C" character from "text" column given in file.csv. The file.csv has two coloumns as ...
3
votes
4answers
721 views

Why doesn't ls combined with awk show exact sizes?

I am trying to find the size of the files on my hard drive in exact bytes, but whenever the size gets too big the number turns all weird (like 1.98329e+12). Can I stop it from doing this or convert ...
2
votes
4answers
185 views

How do I join two CSV files but only where 2nd file matches?

I have 2 CSV files: Objects File: IP,MASK,DESCRIPTION 10.10.3.94,255.255.255.255,Rob 10.10.3.95,255.255.255.255,Mark 10.10.3.96,255.255.255.255,John Services File: DESCRIPTION,OrgIP,Service Rob,1....
0
votes
1answer
29 views

Does GNU awk accept intervals specified using braces in regular expressions?

Which types of regular expressions are recognized by awk? This command echo "aa" | gawk '/a{2,3}/ {print}' does not return anything, whilst echo "a{2,3}" | gawk '/a{2,3}/ {print}' returns a{2,3}....
0
votes
1answer
29 views

reformat file in bash

A file I would like to parse looks like #header #header2 #header 3 # header 1 565286 SNP1-555149 C T . PASS AC=4270AF=1.00;AN=4270;set=broad GT 1/1 /1 ...
1
vote
1answer
25 views

avoiding losing precision with nawk option

I have a data file consists of rows with numeric data. The example of numeric data is 4053.45677771. When I perform arithmetic operation with nawk like; nawk -F, '{print $1*1000}' data > data_2 ...
0
votes
0answers
26 views

Hos to select data with awk?

This is my data: ASP 1 CA ARG 4 CA 0.000 ASP 1 CA THR 5 CA 0.013 ASP 1 CA LEU 24 CA 0.000 ASP 1 CA ASP 25 CA 0.000 .... I want to sort it by column 2 and colum 5, something like this: the number 1 ...
0
votes
1answer
36 views

Cleaning up the output of xev

OS: Openbox session of Lubuntu 14.04 Let's say I run xev and press the Super key, I get a lot of output (>100 lines) and the relevant information is way down the output as seen when I run xev | ...
0
votes
1answer
28 views

extract line from file

a file I need to extract info from looks like 2 41620 . T G 100 PASS AC=3;AF=0.000599042;AN=5008;NS=2504;DP=18872;EAS_AF=0;AMR_AF=0;AFR_AF=0;EUR_AF=0;SAS_AF=0.0031;AA=...
3
votes
4answers
752 views

What is the interpretation of `awk -F':' '$2 ~ “\$” {print $1}' /etc/shadow`?

I was using the command to get the list of users logged in my machine but I can't understand the meaning of the command. awk -F':' '$2 ~ "\$" {print $1}' /etc/shadow
0
votes
3answers
35 views

Convert Number of Decimals Through a Text File

This question's solution may revolve around perl, sed or awk and unfortunately I am not familiar with any of those. My purpose is to convert a computer-generated text file to give it more human-...
0
votes
0answers
49 views

Using AWK to write a CSV file (help me learn it)

I've been struggling with a pdf Directory (list of companies) that was converted with PDFTOTEXT and I would like to convert it's contents with AWK, the input file has the following format: COMPANY ...
3
votes
2answers
225 views

Print unique words, total number of occurrences and sum using `awk`

How can I print unique words, number of their occurrences and the sum of their values in the relevant column using a single array in awk? I'm using awk like: awk -F, '{sum[$1]+=$2} END{for (x in sum)...
0
votes
1answer
56 views

Please explain what does following command mean:

awk -F'[ ()+:]+' ' I use it in my script. With this case I can take the time in brackets from for example: Fri Dec 18 11:13 - 11:15 (00:02) Fri Dec 18 09:11 - 19:42 (1+10:31) But how does it ...
2
votes
4answers
153 views

Extract Strings from an HTML file

I need an sh script will get text from an html file I download the file with wget website.com/link_123456789 -O 'testfile.txt' the full contents of that file are located at this pastebin But you ...
0
votes
1answer
18 views

using prinf function for repeated patterns

I have codes which append the patterns into text file w.r.t. the user's input as follows; echo -n "WHICH STATIONS?" read station awk -v input="$station" ' BEGIN { n = split(tolower(input), ...
0
votes
1answer
191 views

Do I need to install awk or is it inbuilt in Ubuntu?

I'm new to Linux OS and studying Mobile Computing. I have to analyze files using awk. I'm using Ubuntu 14.04. Do I need to install awk or is it inbuilt in Ubuntu?
2
votes
1answer
43 views

Cron Job Produces No Output

I am using the following cron entry to clean my Postfix queue: * * * * * mailq|awk ' /^[0-9A-F][0-9A-F]*.*MAILER-DAEMON$/ {print $1}'|tr -d '*'| xargs -rn1 /usr/sbin/postsuper -d > output.txt ...
5
votes
4answers
632 views

Merge files using a common column

I have two files out of which I want to create a third which contains all the information. file 1: a 111 b 222 c 333 d 666 e 777 file 2: 111 x1 222 x2 333 x3 444 x4 555 x5 666 x6 777 x7 ...
1
vote
0answers
75 views

How to run a tail -f log monitor script as a systemd service

I have a shell script which monitors the auth log to alert on new system logins, and it works fine when I start it manually, but when I try to load it as a service using systemd service is fails to ...
2
votes
2answers
227 views

Merging/joining a lot of csv files with numeric digits in the file name

As we process our csv data, we generate a lot of output files with 30 000 lines in each one of them. They all have the same columns/fields. They are all also in csv format and we put them into the ...
0
votes
1answer
53 views

Trying to convert a simple C program into an AWK program [closed]

Hey guys a couple of weeks ago I wrote a C program that prompts the user for the name of a text file and then prompts the user for a word. The program then outputs the input text file with numbers to ...
2
votes
1answer
97 views

awk command unable to read apache log file (user error)

Stumped by this one: less, cat & grep are all able to list the content of an apache log file "/var/log/apache2/other_vhosts_access.log". But when I use awk to grab the last 5 minutes of the file ...
0
votes
1answer
57 views

Alias in .bash_aliases executes incorrectly

I have an alias in .bash_aliases and it gives me incorrect output when I trigger it. alias print="echo a b | awk '{print $2}'" incorrect output: slazer@ubuntu:~/Desktop/xpalenik_pb161/hw03/...
3
votes
3answers
8k views

Extract word from string using grep/sed/awk

I have a string 00:28:04 /usr/lib/jvm/jre/bin/java -DJDBC_CONNECTION_STRING= -Dspring.profiles.active=qa -XX:MaxPermSize=256 and want to extract the word qa that follows -Dspring.profiles.active. ...
2
votes
1answer
49 views

Complicated text manipulation with awk

I have a heavy text with a pattern as below it starts with ------------------ MOLECULAR ORBITALS ------------------ 0 1 2 3 4 5 ...
1
vote
2answers
32 views

remove 2nd line of output using awk

I have the following output: Filename:xxxxxxxx date: 2014/12/24 14:46:41; author: xxxxx; state: Exp; lines: +210 -206 date: 2014/11/18 21:00:43; author: xxxxx; state: Exp; lines: +617 -594 ...
4
votes
3answers
280 views

How I can count how many repeated numbers in a file and then organize them by repetitions?

I have a file that needs organized a number of repeats, my file has 6 rows and 3120 lines each member has 1 or 2 digits, total 18720 numbers with one or 2 digits. I would like to count how many 1, ...
1
vote
1answer
201 views

Problem extracting data from file using awk

I have a large data file and want to split it into smaller files based on values in column 1. For example column 1 has numbers from 1 to 10 ten times to make 100 rows and I want all lines with numbers ...
5
votes
4answers
261 views

Read the table after a specific line and count occrences with awk

I have a table somewhere in a big log file which looks like this example: ---------------------------- CARTESIAN COORDINATES (A.U.) ---------------------------- NO LB ZA FRAG MASS ...
0
votes
1answer
26 views

Compare and count in ubuntu

I have a file with 2 columns like this: Product Cost ab 5 ab 7 bl 1 bl 8 ce 4 I want to search for "ab" and "bl" and then need to sum up the Costs for them and ...
-6
votes
2answers
58 views

Getting number of users depending on their age [closed]

I have a text file in which there are two columns: Name Age Ashko 32 Mohan 45 arun 21 I want to get the number of users whose age is greater than 25 ex 2 in above case
1
vote
4answers
144 views

awk repeats lines too many times

I'm using awk to create a file that contains lines of text & uses an input file of numbers. I want to substitute each number once, i.e. line 1 gets the first number, line 2 gets the second number, ...
-1
votes
2answers
86 views

substitute values in one text file into another text file

I want to use awk to create a text file that includes a series of awk text lines with numbers that are replaced in. problem i am having is that the text will include awk syntax. ultimately, i want to ...
0
votes
0answers
113 views

awk add certain colum if two columns are similar

First at all I apologize, but I am a newbie in scripting, and I try to learn something. I have a file which looks like this: 1 A 84.54 47355 1281 1 A 80.16 47355 761 1 A 81.63 ...
3
votes
2answers
78 views

tee results in a null file

I try to change Apache configuration with this: sudo awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}' /etc/apache2/apache2.conf | sudo tee /etc/apache2/...
0
votes
2answers
298 views

Extract numbers with awk

a part of a script in awk looks like this sub(/^Mutation: {"seq-pos":/,"") && sub(/, "time":/," ") && sub(/}$/,"") { print >"fifth_"FILENAME} The aim is that given this input:...
2
votes
2answers
92 views

Search for number sequence

say you have a file1.csv containing 5 million lines, each line has 8 random numbers separated by comma. And you have this sequence 7,152,13,11,42,5,7 How to output the lines in file1.csv containing 3 ...
2
votes
2answers
361 views

How to merge values from two different text files?

I have following data set in text files: file1.txt a1:b1 a2:b2 a3:b3 a4:b4 a5:b5 file2.txt b2:c1 b4:c2 b5:c3 How to merge these values to make output file like this: output.txt a2:c1 a4:c2 a5:...
-1
votes
1answer
31 views

read numbers with e in awk

Hello a file I am working with looks: header // SeqT: {"POS-s":174.683, "time":0.0130084} SeqT: {"POS-s":431.49, "time":0.0221447} [2.04545e+2]:0.00843832,469:0.0109533):0.00657864,((((872:0....
2
votes
3answers
206 views

How can I divide an output with 2 delimiters?

By dividing with the "·" and " " characters, I would like to turn this: Hel·lo my name is E·ric To this: Hel·lo my name is E·ric Hel·lo my name is E· Hel·lo my name is Hel·lo my name Hel·lo my Hel·...
0
votes
1answer
99 views

split files with specific pattern

A file I work with is like NAMES n0 n1 n2 n3 n4 n5 n6 n7 REGION chr 1 100000 404 AAAAAAGA 992 TTTTTTTA 1146 CCCCGGCC 1727 CCCCCACC 1778 GCCCCCCC My desired output is (please ...
1
vote
1answer
430 views

How to restrict the decimal places in awk without rounding off

I want to print 0.74 for 0.748. If I use awk '{printf "%0.2f\n",$1}' filename for 0.748 it prints 0.75. But I want 0.74 and remove remaining part. For 77.348 it should be 77.34. Any ideas? ...
0
votes
2answers
113 views

How to skip a record with awk

I have a large number of files in a log-directory, whose names were time-stamped (in this case with date +%b[...]). I want to write a POSIX compliant one-liner that will: either skip lines output ...
1
vote
7answers
798 views

Remove duplicated dots from file name

I have a dir with tons of files inside which have been named in malformed such as file..txt ,file2..txt ,etc... So how to easily remove this second . from file names? Any applicable method is ...
2
votes
4answers
180 views

Remove whitespace from all array elements

I have a array called arrayvar, which is being defined as arrayvar=( $(awk '/'"$vovar"'/,/}/ {gsub("'"$vovar"'"," "); gsub("}"," "); gsub("{"," ");gsub(","," ");print}' temp1 | tr -d '\n' | sed 's/^...