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

learn more… | top users | synonyms

3
votes
4answers
568 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
26 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 ...
0
votes
0answers
30 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
142 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 ...
0
votes
1answer
46 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 ...
1
vote
3answers
42 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
151 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
35 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
322 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
35 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 ...
1
vote
2answers
76 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
43 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
56 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
42 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: ...
2
votes
3answers
1k 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
44 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
28 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
244 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
144 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
208 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
23 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
54 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
118 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
71 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
93 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
68 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 ...
0
votes
2answers
108 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 ...
2
votes
2answers
90 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
278 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 ...
-1
votes
1answer
28 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
votes
3answers
199 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 ...
0
votes
1answer
79 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
169 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
77 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
679 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
143 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 ...
2
votes
1answer
419 views

Passing Variable into awk gsub

I have this command Here vovar=OBJECTS prvar="$(awk '/'"$vovar"'/,/}/ {gsub("$vovar"," "); gsub("}",": %s,"); gsub("{"," ");gsub(",",": %s,");print}' temp1)" Contents of temp1 ...
1
vote
2answers
116 views

Make echo ignore spaces?

I have a file called temp1 sCellEventTrap-03-27 TRAP-TYPE -- CAC Code: 01 ENTERPRISE compaq VARIABLES { scellNameDateTime, scellSWComponent, ...
1
vote
1answer
74 views

diffrence between two files of different row numbers

Yesterday I asked this question, and got awesome answers, it's really a joy to ask questions on this site. Today I got a slightly different question say I have csv1 1,2,3,4 5,6,7,8 -- 9,10,11,12 ...
0
votes
4answers
62 views

Adding a number to a already present variable sed/grep/awk

I have this in file.txt FORM: lookupfile Version: 1 LookupFile:"$i" How can I find this in the file and add a variable b to the $i. So example INPUT FORM: ...
10
votes
5answers
1k views

Difference of two big files

I have "test1.csv" and it contains 200,400,600,800 100,300,500,700 50,25,125,310 and test2.csv and it contains 100,4,2,1,7 200,400,600,800 21,22,23,24,25 50,25,125,310 50,25,700,5 now diff ...
1
vote
3answers
243 views

retain white spaces in fields when using awk

I am using nawk on a pipe delimited file to print fields as index and key where some of the fields contain white space, when there is no white space everything works normal, but in case of white ...
-1
votes
4answers
79 views

Copy a string occurring before a particular pattern.

I am to copy this emuEventTrapInformative from below. -- Traps emuEventTrapInformative TRAP-TYPE ENTERPRISE compaq VARIABLES { scellNameDateTime, shelfId, ...
0
votes
3answers
66 views

Print a string a number of times [closed]

I have a variable numvar which contains a number. CODE something that reads number stored in numvar and then creates the same number of sTrapValue[with a number here that incrementally ...
-2
votes
2answers
89 views

Delete lines between 2 strings

I am to delete all stings from starting of file to a certain point using anything, sed, Grep, awk in shell INPUT sCSISmart20 TRAP-TYPE ENTERPRISE cyclone ...
2
votes
5answers
156 views

Condition that matches all occurrences of a word in a file ad does something

I am to do something like this for (( every occurrence of the word TRAP-TYPE in a file )) do desc="$(< inputfile awk '/DESCRIPTION/ {getline; gsub(/^\s*"/, ""); gsub(/"\s*$/, ""); print}')" ...
3
votes
5answers
336 views

sed remove last 2 numerals

I have the following. oid=.1.3.6.1.4.1.795.2.5.0.xxx (these 0.xxx represent any random numeral) I want to do the following echo $oid | sed (some commands to remove 0.xxx) and store the resulting ...
2
votes
3answers
260 views

How to delete lines starting with certain strings

Is there a way to delete lines starting with certain strings. I have this youtube-dl code youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 ...
3
votes
1answer
539 views

youtube-dl file download progress with zenity progress bar

How to add youtube-dl file download progress percentage to zenity progress bar sample code (just an example, not a working one) #!/bin/sh ( progress=$(youtube-dl --extract-audio --audio-quality 0 ...