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
2
votes
1 answer

Logging varnishlog output to a file with awk in daemon mode

I would like to daemonize the answer in this topic https://serverfault.com/a/480871/94127. Since varnishlog has daemon mode, I tried to use -D option as below. But the timestamps are not appearing. varnishlog -I "Back healthy|Went sick" -w…
antimatter
  • 229
  • 1
  • 7
2
votes
3 answers

linux + match only VALID IP from text file into other file

please advice how to match only the valid IPs ( 255.255.255.255 ) from the file.txt and insert only the valid IP into VALID_IP.txt file ( see VALID_IP.txt for example ) the solution should be implemented in my ksh script ( so perl or sed or…
yael
  • 2,433
  • 5
  • 31
  • 43
2
votes
3 answers

How to find largest files in a dir - ignoring directory sizes

I want to do something like this du -a | sort -rn | head But I want to extract files only, ignoring directories. To be clear, I want to traverse through all sub-directories but I don't want to find directory sizes. Just files sizes. UPDATE I also…
denormalizer
  • 491
  • 2
  • 5
  • 15
2
votes
1 answer

Writing to /etc/networking/interfaces at boot using sed/awk?

Newbie here, I'm trying to write to an auto-generated /etc/network/interfaces file of a newely provisioned XEN Ubuntu (12.04/10.04/8.04) DomU server at boot time using (currently) sed. The auto-generated file is formatted as below: auto eth0 iface…
Colin
  • 21
  • 3
2
votes
1 answer

Memory usage REGEX

Could you help me to modify the following one-liner to get more precise memory usage - right now it's just an integer I would like to include first value after coma. free -m | awk '/Mem:/ {tot = $2;} /cache:/{printf "%d\n", $3 / tot * 100}' Thank…
HTF
  • 3,148
  • 14
  • 52
  • 82
2
votes
2 answers

Gathering IP's from a complicated log

I have a question regarding the use of some more advanced grep, awk, sed. I have a log file, for a proprietary MTA, that contains IP's in a string, delimited by [redacted]^~x.x.x.x^[redacted]. So far all of my grepping, awking, and sedding hasn't…
Harry
  • 128
  • 5
2
votes
2 answers

Display nth instance of grepped pattern

So here's my problem. I have an issue with a .csv file (Current.csv) in that there are commas randomly place throughout the data, so awk-ing the file doesn't give me constant column numbers for a particular type of information I'm looking for. …
user121351
2
votes
2 answers

awk + perl + get two arguments in to awk syntax

please advice what wrong with my awk syntax and how to fix it ( this syntax is in my ksh script ) and I run my script on linux machine my target is to get from the file.txt only the lines that between the dates: FROM 2012-04-19 TO …
yael
  • 2,433
  • 5
  • 31
  • 43
2
votes
2 answers

Grep to find lines starting at pattern A until pattern B is matched

I have a log that contains bits like this: [2012-04-16 15:16:43,827: DEBUG/PoolWorker-2] {'feed': {}, 'bozo': 1, 'bozo_exception': URLError(error(110, 'Connection timed out'),), 'entries': []} [2012-04-16 15:16:43,827: ERROR/PoolWorker-2]…
Steve Bennett
  • 5,750
  • 12
  • 47
  • 59
2
votes
3 answers

alias to replace a text in file

here is a practical situation.I facing some of my files where there is a common string in these files.I usually will open vi and do some thing like :%s/text/replacement/g and I have to do it in many files many many times. Is there some easy way…
Registered User
  • 1,463
  • 5
  • 18
  • 37
2
votes
3 answers

Passing variables problem - Bash

I have a following problem: #!/bin/bash NUM=`cat accounts | wc -l`; for i in {1..$NUM} do account=`awk "NR==$i" accounts`; echo -e "\nAccount: $account\n"; sudo ./backup_maildir $account; done "accounts" is a file with regular e-mail…
Boban P.
  • 705
  • 1
  • 6
  • 20
2
votes
3 answers

Shell script to block proftp failled attempt

I want to filter and block failed attempt to access my proftp server. Here is an example line from the /var/log/secure file: Jan 2 18:38:25 server1 proftpd[17847]: spy1.XYZ.com (93.218.93.95[93.218.93.95]) - Maximum login attempts (3) exceeded …
Minhaj
  • 177
  • 4
  • 14
2
votes
2 answers

Best way to filter output by date range

I need to filter a row of a csv file by a date. The file is structured as so: test121smith@example.com active 01/24/11 10:04 07/23/23 16:56 test121johnson@example.com …
dj423
  • 23
  • 3
2
votes
1 answer

Possible to parse ldapsearch output?

I have an ldapsearch query to pull some data of an email system, I am trying to parse the data into something I can analyze in a table/flat file, and generate reports on the accounts. Sample of the ldapsearch output: # scott, people,…
dj423
  • 23
  • 4
2
votes
2 answers

Convert lscpu output to row based format in excel/csv table format

I have the below data (lscpu output) for 1000 servers and I want the same in excel but in row format and not as in command output in columns 1.2.3.4 CHANGED Architecture: x86_64 CPU op-mode(s): 32-bit,…
Loki
  • 21
  • 2