Questions tagged [awk]

The AWK utility is a data extraction and reporting tool that uses a data-driven scripting language consisting of a set of actions to be taken against textual data (either in files or data streams) for the purpose of producing formatted reports.

The AWK utility is a data extraction and reporting tool that uses a data-driven scripting language consisting of a set of actions to be taken against textual data (either in files or data streams) for the purpose of producing formatted reports. The language used by awk extensively uses the string datatype, associative arrays (that is, arrays indexed by key strings), and regular expressions.

AWK was created at Bell Labs in the 1970s, and its name is derived from the family names of its authors — Alfred Aho, Peter Weinberger, and Brian Kernighan.

194 questions
1
vote
1 answer

How to substitute a string from an awk result?

I have a JSON file which contain multiple occurrence of replaceme. I only want to substitute an occurrence based on a specific string found a few line above. E.g., [...] "title" : { "Propertie1" : "xxxx", "Propertie2: "replaceme" …
Bastien974
  • 1,896
  • 12
  • 44
  • 62
1
vote
1 answer

Get some meaning from apache logs with awk and grep

I am trying to have some meaning from my apache log files: I want to parse my access log and have some statistics about 200 status code hits (how many times each of them was hit). So I tried to learn some awk magic and here what I got right…
Salvador Dali
  • 965
  • 6
  • 20
  • 31
1
vote
3 answers

drop ips with iptables from awk result

I have a log file like this : Frq:15 IP:0.0.0.0 Date: 2014-03-21 12:19:31 AM Frq:9 IP:198.252.206.25 Date: 2014-03-21 12:19:31 AM Now i get column of ip addresses with awk : cat /tmp/test | awk '{print $2}'|awk '{gsub("IP:", "");print}' And the…
1
vote
1 answer

Search log files newer than a time

I have a log file which has entries like below. I want to find only the log entries newer than a given time. What would be a suitable shell script for it? [2013-06-23 21:31:19,972] INFO [2013-06-23 21:31:20,148] INFO [2013-06-23 21:31:20,148] …
1
vote
2 answers

How to use AWK to generate bandwidth report in Apache

I have my Apache logs set up like this: LogFormat "%v %t %I %O" billing How can I use AWK to generate a report which shows me the total bandwidth (received + sent) in MB per virtual host? Here's an example log output: bob.com [3 JULY 2013] 903…
James
  • 13
  • 3
1
vote
2 answers

Yum command to downgrade packages

I need to downgrade php on a server and found the command below. Something seems to be wrong with the syntax. yum downgrade $(rpm -qa --qf "%{NAME} " | \ grep -v ioncube | grep ^php | awk '{print $1"-5.2.17"}') I get the following…
ddjammin
  • 33
  • 1
  • 5
1
vote
3 answers

tail-pipe-awk script, fine on Centos but weird on Ubuntu

I wrote a script on CentOS and now I'm trying to run it on Ubuntu and it is behaving unexpectedly. Here's something like the script, which I run under bash: sudo tail -F /var/opt/my-application/log/my-application.log | awk ' BEGIN { ORS=" " } {…
jg3
  • 169
  • 1
  • 6
1
vote
2 answers

looking for a tricky one liner to get diff of awk output

Lets say i have two files like below: file1 a 23 b 34 c 47 file2 a justin_beiber_sucks b segmentation fault c jackson d nop Now what i want is to get a diff of the first column of two file. I'm doing it now like $cat file1 awk '{print $1}'>…
Aftnix
  • 233
  • 2
  • 8
1
vote
2 answers

linux or solaris match files with uniq syntax

how to match all files that start with the string OS_PATCH and ended with .gz remark - the solution must to fit Linux and Solaris OS this task could be by find command or maybe with ls with Regular Expressions or any other idea for example…
yael
  • 2,433
  • 5
  • 31
  • 43
1
vote
2 answers

Using wget and Awk to count similar expressions

I am trying to create a script that uses wget to download a data set and then awk to sort though the file and tell you the most common filter used which is $14 column. So far I have the wget function working as seen below, wget -O-…
kevin jack
  • 11
  • 2
1
vote
3 answers

append to end of line sed / awk

This is probably easy and something is not clicking for me and my lack of coffee right now. I have a file with multiple lines that begin with a tab then the word GROUP something { Some of these lines for whatever reason drop the curly bracket under…
egorgry
  • 2,871
  • 2
  • 23
  • 21
1
vote
5 answers

Extracting lines from a file based on prefix

I need to extract all lines from file2 that begin with an id # prefix contained in file1. File 1 is single column like: 324 399 408 135236 321590 File 2 is multi-column like: 1 [tab] 108 [tab] Anarchist [tab] 103985 ... 324 [tab] 309 [tab] Melodies…
Poe
  • 321
  • 1
  • 5
  • 18
1
vote
4 answers

double awk commands in same pipe?

Hello I'm trying to do something like this but it wont work, can you guys tell me help me out? /usr/bin/mysql -B -r -h ******** -u******* -p****** -D***** \ -e'SELECT `username`, `uid`, `gid`, `homedir` FROM `some_table`)' | \ awk…
Apaz
  • 43
  • 4
1
vote
1 answer

Using Find, Grep, Awk, or Sed To Rename Server After Cloning

My client tells me they have cloned a VM in VMWare of an Ubuntu Linux server. Now it's my job to get into all the files and find out what still has the old server name of "bishop" and change it to something else. Also, the IP address is changed and…
ServerChecker
  • 1,518
  • 2
  • 14
  • 35
1
vote
4 answers

Bash: delete all but most recent n files with prefix x

I have a directory of backups that looks like this: -rw-r--r-- 1 ftpuser ftponly 5610595 May 27 00:01 alpha-114.tar.asc -rw-r--r-- 1 ftpuser ftponly 50559368 May 27 00:04 beta-211.tar.asc -rw-r--r-- 1 ftpuser ftponly 61320807 May 27…
Frank Brenner
  • 175
  • 5
  • 11