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.

184 questions
73
votes
12 answers

Do you have any useful awk and grep scripts for parsing apache logs?

I can use log analyzers, but often I need to parse recent web logs to see what's happening at the moment. I sometimes do things like to figure out top 10 ips that request a certain file cat foo.log | grep request_to_file_foo | awk '{print $1}' | …
deadprogrammer
  • 1,661
  • 7
  • 24
  • 25
56
votes
9 answers

How to split a PEM file

Note : This is not really a question because I already found the answer but since I didn't find it easily here I will post it so that it can benefit others. Question : How to read a concatenated PEM file as the one used by apache/mod_ssl directive…
Cerber
  • 1,101
  • 1
  • 10
  • 23
51
votes
8 answers

bash/sed/awk/etc remove every other newline

a bash commands outputs this: Runtime Name: vmhba2:C0:T3:L14 Group State: active Runtime Name: vmhba3:C0:T0:L14 Group State: active unoptimized Runtime Name: vmhba2:C0:T1:L14 Group State: active unoptimized Runtime Name: vmhba3:C0:T3:L14 Group…
carillonator
  • 805
  • 3
  • 12
  • 22
49
votes
7 answers

How to get all fingerprints for .ssh/authorized_keys(2) file

Is there a simple way to get a list of all fingerprints entered in the .ssh/authorized_keys || .ssh/authorized_keys2 file? ssh-keygen -l -f .ssh/authorized_keys will only return fingerprint of first line / entry / publickey hack with awk: awk…
childno͡.de
  • 631
  • 1
  • 5
  • 14
32
votes
8 answers

how to find out mac addresses of all machines on network

Is there some easy way to find out mac address of all machines on my network rather than doing an SSH into each and ifconfig | grep HWaddr if there are 300 machines on network I really need some easy solution.
Registered User
  • 1,453
  • 5
  • 18
  • 37
21
votes
3 answers

iptables show just one chain

tldr: How can I get iptables to show just one chain? I can have iptables show just one table, but a table consists of multiple chains. I need to find where in chain INPUT is the last rule (usually but not always the REJECT all rule). I've tried awk…
bgStack15
  • 911
  • 1
  • 9
  • 23
20
votes
4 answers

Linux shell command to filter a text file by line length

I have a 30gb disk image of a borked partition (think dd if=/dev/sda1 of=diskimage) that I need to recover some text files from. Data carving tools like foremost only work on files with well defined headers, i.e. not plain text files, so I've fallen…
Li-aung Yip
  • 413
  • 1
  • 4
  • 9
20
votes
3 answers

Best way to get the MAC of eth0?

Is there a more efficient way to retrieve the MAC address of a NIC in Linux? This works: ip link show dev eth0 | awk ' /link\/ether/ { print $2 }' but can it be found via something like: cat /sys/net/something
brodul
  • 323
  • 2
  • 7
18
votes
7 answers

How to parse and convert ini file into bash array variables?

I'm trying to convert an ini file into bash array variables. The sample ini is as below: [foobar] session=foo path=/some/path [barfoo] session=bar path=/some/path so these…
Flint
  • 631
  • 5
  • 10
  • 18
17
votes
8 answers

Can awk be used instead?

I would like to get the number from rating as output from this # nc localhost 9571 language: language:en_ZA.UTF-8 language:en_ZW.UTF-8 session-with-name:Ubuntu Classic (No effects):gnome-session --session=2d-gnome session-with-name:Ubuntu (Safe…
Sandra
  • 9,973
  • 37
  • 104
  • 160
16
votes
3 answers

How to delete all characters in one line after "]" with sed?

How to delete all characters in one line after "]" with sed ? Im trying to grep some file using cat, awk. Now my oneliner returns me something like 121.122.121.111] other characters in logs from sendmail.... :) Now I want to delete all after "]"…
B14D3
  • 5,110
  • 13
  • 58
  • 82
15
votes
5 answers

remove line break using AWK

I am facing some problem regarding my bash script. Below is my bash code : #!/bin/bash cd /root/Msgs/TESTNEW/new file=myfile.txt var1=$(awk '(NR==30){print $2}' $file) var2=$(awk 'NR>=38 && NR<=39' $file) var3=${var2// /+} curl…
user119720
  • 380
  • 3
  • 6
  • 19
8
votes
5 answers

How to remove a certain symbol for a bash script

I have a bash script where I get the disk usage, for example 60%. How can I remove the % symbol? Using grep or awk?
pmerino
  • 391
  • 1
  • 4
  • 11
7
votes
5 answers

Calculate sum of several sizes of files in Bash

I have list of files in a file, cache_temp. In file…
Piduna
  • 501
  • 3
  • 10
  • 23
7
votes
1 answer

Why don't random numbers in AWK change after the first run?

I'm studying AWK, and when I use the following command for the second time why are the numbers always the same? First time run: awk 'BEGIN{for(i=1;i<=10;i++) print int(101*rand())}' 24 29 85 15 59 19 81 17 48 15 Second time run: awk…
c4f4t0r
  • 5,149
  • 3
  • 28
  • 41
1
2 3
12 13