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
0
votes
2 answers

Shell Script to check CPU Utilisation

I am trying to write a shell script which will check free memory of the server. I am trying below code top -M -n1 | grep "Mem" | awk '{print 0 + $7}' | awk '{ print $1 / 1024 }' | awk '{if ($1 < 1) print "\n Available Free memory is " $1…
Shyam
  • 1
0
votes
1 answer

Limit awk results to html requests

I'm using awk to analyze some access log files. I'm currently using the following: awk '($9 ~ /404/)' access_log | awk '{print $9,$7}' | sort | uniq -c | sort > 404.txt Which returns all of the 404s in my access log with number of appearances.…
Vecta
  • 103
  • 2
0
votes
2 answers

Print last column containing spaces and special characters

I need a full path/command thats been execued to start a process thats exposed on the network - listens on tcp/udp . I did manage to get all of that using below "one liner": netstat -nlp46|tail -n +3 | while IFS=" " read -r -a line; do…
Pavel K
  • 78
  • 6
0
votes
1 answer

Executing command remotely on another linux server from a shell script

I have a shell-script which extract details from a log file between two dates and executes a command on the output to generate some report.The log files are on different server and scripts are executed on different server. the Script looks like : …
anand
  • 152
  • 6
0
votes
1 answer

within awk how to check for a defined value before attempting a calculation

The following awk line will fail when c15 is not defined or is 0. How to modify it so that in such cases it does not attempt the calculation, but instead provides an error message or does nothing: cat formatted.dsv | awk -F"\t" '{ c12 = $12; c15 =…
Michael Martinez
  • 2,645
  • 3
  • 24
  • 35
0
votes
1 answer

Pipe lsof to grep to awk ps -ef to grep

I'm trying to get some info on a certain PID. I'm probably doing this in a manner that is way too difficult, but I'm trying to run this: lsof | grep grepstuff | awk '{ps -ef | grep $2;}' and I'm not getting anything in response. If I remove the awk…
Sugitime
  • 415
  • 1
  • 4
  • 12
0
votes
3 answers

Modify config file settings from bash

I need to modify a config file from a bash script, changing the values of particular settings. I need to make the change using common Linux tools (sed/awk/tr/etc.). The config file can have identically named keys in different stanzas like…
TSG
  • 1,674
  • 7
  • 32
  • 51
0
votes
2 answers

Replace date in epoch (seconds) format to normal in a log file

I am on a ubuntu machine trying to read from log files and found the logs contain date and time in epoch format(seconds). How can I convert these dates in numbers into any readable format from command line? 1411622206, HOST ALERT,…
0
votes
2 answers

How to print regex match

My problme is two fold. First is printing a regex match. The second is the actual regex. Problem 1: I'm trying to print the output of yum grouplist --verbose into a format that I can put into a puppet conf file. Therefore, I need to print more than…
chizou
  • 477
  • 3
  • 8
  • 18
0
votes
1 answer

Eliminate need for grep use only awk

I am trying to generate a list of PID's to pass to strace I only want the PID's php-fpm. I can get the correct output by using grep with awk but am looking for an awk only answer. Here is what I have done. This gives the desired output: $ ps ajxf…
menders65
  • 25
  • 6
0
votes
2 answers

Script for search string inside the file for every one hour

I need to write a script where the particular string(alphanumeric) should be searched inside the file with every hour for whole day. And the search should not contain the previous hour results. Time stamp format inside file is "2014-02-17…
user197719
  • 191
  • 1
  • 4
0
votes
2 answers

Invalidating email addresses from sql dump before import

Synopsis I would like to import production data into the development environment so testing can be done in an almost accurate way. Of course I need to invalidate e-mail addresses as I don't want e-mails reaching the end-user. Source Just a side note…
Ash
  • 471
  • 1
  • 4
  • 14
0
votes
3 answers

Tinydns data file change ip with bash

I am using tinydns and need to dynamicly change some ip in data file. I want to use bash script for it. For example data…
Andrei Nikolaev
  • 95
  • 1
  • 2
  • 5
0
votes
1 answer

Parse requests per OS type apache log

I'm trying to return a sorted list of requests per OS type, parsed from an Apache access_log file (not combined format as I need the user-agent info). Here's an example of the output I'm looking for: 250 Windows NT 6.1; WOW64 200 X11; Linux…
Alex
  • 25
  • 7
0
votes
1 answer

Changing Zone files with sed

I have this dns zone file I was unable to change the resource record type A to CNAME @ IN SOA ns1.domain.com. webdev.domain.com. ( 2006080101 ; serial 8H ; refresh 2H ; retry 1W ; expire 4h)…
Kahiye
  • 1
  • 1