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
7 answers

How to show available disks on a Linux system?

If i run fdisk -l I get an output as: Disk /dev/sda: 120.0 GB, 120034123776 bytes 255 heads, 63 sectors/track, 14593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x0003ad9d Device Boot Start End …
Uthman
  • 263
  • 2
  • 5
  • 13
2
votes
1 answer

Extract a ids from text file

I have a text file live below { "data": { "assigned-entity-id": null, "assigned-entity-type": null, "availability-domain": null, "compartment-id": "ocid1.tenancy.oc1..dgfmmnusmgibmkdomuijsngimimfimfgiufmgifmdsfsdsgsmgsifmg", …
Am3Y
  • 67
  • 6
1
vote
3 answers

text processing linux using grep awk or anything else

I want to replace in this string Wed Apr 10 06:44:10 UTC 2019 all whitespaces with comma and along with that trim off UTC part. What I have tried : var1="Wed Apr 10 06:44:10 UTC 2019" echo ${var// /,} This gives all spaces removed but how to trim…
Alex
  • 172
  • 1
  • 1
  • 8
1
vote
1 answer

regex: match two /'s back from end of line

I have a file of file paths. The depth of the directories is of various lengths and path names. I'd like to match two directories backwards (two /'s) and delete the match, creating a new file with the…
Greg-905
  • 13
  • 2
1
vote
1 answer

How can I use an iperf output and only grep Interval and Bandwidth?

I am trying to get the output from the command iperf -c 10.0.0.1 -t 3600 -i 2 And only need the Interval and bandwidth fields listed for the entire hour of logging. I haven't used grep or awk in years upon years. Help would be awesome! Sample…
Gutsygibbon
  • 113
  • 1
  • 6
1
vote
3 answers

Grep last match from file

I'm running the following command against a log file and only wanting to get the last/latest match. Sometimes there may only be one match, other times there may be multiple, which is causing an issue for me since the following command is returning…
Godzilla74
  • 135
  • 1
  • 7
1
vote
5 answers

bash script - print from line N to EOF

I want to be able to print the number of lines from bash as such: Line number (as counted from the top) -> end of the file It seems tail will only count lines from the bottom. Does anyone know how to do this? Thanks. I've tried the following # Where…
bobinabottle
  • 579
  • 2
  • 7
  • 19
1
vote
2 answers

How to extract the last two (or any number) directories from a path with sed?

I'm really looking for a generic solution here, but for the sake of example, let's say I'm looking for the deepest 2 directories in a path. e.g.: Given a path /home/someone/foo/bar, how can I use sed (or awk) to get foo/bar It would be simple if the…
steve c c
  • 158
  • 5
1
vote
1 answer

multiline into single line and output to logger

I have a log file where data entries are as follows Each entry starts with time: time: 20170509123420 dn: uid=abc,ou=People,dc=test,dc=example,dc=com changetype: modify replace: passwordAllowChangeTime replace: passwordExpirationTime replace:…
kathir
  • 96
  • 9
1
vote
2 answers

How to retrieve first N and last M lines from input in fish?

I have an input like: 1 2 3 4 5 6 7 8 And I'd like to retrieve only N first and M last lines from this input. For example, if N is 2 and M is 4 I want the result to be: 1 2 5 6 7 8 Lines can overlap, so if N is 6 and M is 4 I want the output to be…
Jezor
  • 113
  • 5
1
vote
1 answer

How to write a shell script to search from a position in file instead to start from beginning of the file again

I am trying to write a shell script to find value stored after a repetitive word in a big file with millions of lines using for loop. After the finding the repetitive word how i make script to start searching after the present line in file so that…
1
vote
1 answer

Running CAT in SCREEN no output to file

I am trying to code this command to run in screen along with 2 others that will be using cat to read a file then pipe it into awk for filtering. Here is the command; screen -d -m /bin/cat /var/www/html/filter/unfiltered.txt | awk '{print $1}' >…
LinHost
  • 39
  • 5
1
vote
2 answers

Special char or wildcard in awk field separator

Would appreciate to know about the special char or wildcard in the following command: /sbin/ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}' What does the code below mean? awk -F ' *|:' '
krock1516
  • 128
  • 1
  • 5
1
vote
1 answer

How to using sed to change the last character from a match line

How to using sed to change the last character from a match line ? Exemple: /etc/network/interfaces auto eth0 iface eth0 inet static address 150.0.3.50 netmask 255.255.255.0 network 150.0.3.0 gateway 150.0.3.6 auto…
rodolpho
  • 23
  • 4
1
vote
0 answers

how to filter sar -d disk output tidily

sar -D output-I would like a suitable command to run alongside stress -hdd but this is the output which sar -D 1 10 gives. I have filtered it using both awk |'NR > 1 {printf "%4s%8s%8s\n",$13,$14,$15}' and awk 'NR > 1 {OFS="\t"; print $13,$14,$15}'…
Rory
  • 11
  • 2