Some very useful tips when working with IP addresses on the Internet.

Get the IPv6 address of a website very easily with this simple one-liner. jason@. PWD: ~. -bash. 3.2.57. 29 $> host ipv6.google.com | awk ‘FNR==2 {print $5}’ 2404:6800:4006:811::200ejason@. PWD: ~. -bash. 3.2.57. 29 $> host ipv6.google.com | awk ‘FNR==2 {print $5}’ 2404:6800:4006:811::200e This works just fine to get the required…

Read More

How to add a column heading with awk on Linux.

This very nice one-liner will print some information about your mounted drives on Linux and also print a column header to dress up the output. ┌──[[email protected]]─[~/Downloads] └──╼ ╼ $ df -Hla | grep "[0-9]% /" | awk -F, ‘NR==1 {print "Device","Capacity","Free","Usage","Percentage","Mount"} {gsub(/"/,""); print $1,$2,$4}’ | column -t Device Capacity Free…

Read More

Very useful bash awk scripting tricks.

Awk and bash are a very good combination for extracting certain text strings from a text file or the output of a program. Here I am extracting only the values that are surrounded by square brackets. 4.4 Mon Jan 27 jason@Yog-Sothoth 0: $ lspci | awk -vRS="]" -vFS="[" ‘{print $2}’…

Read More

More very useful tricks with awk on Linux.

Printing user information such as the username and home directory for each user on your system is very easy with awk. Use this simple post to get this information. This will help you out if there are a lot of users on your system and you wish to list them all.

Read More

Another way to get the actual IP address of your machine.

This is yet another way to get the actual IP address of your Linux machine on a LAN. This returns just the IP address of your Linux computer. jason@jason-Lenovo-H50-55:~$ ip a | awk ‘/inet / { print $2 }’ | sed -n 2p 192.168.1.4/24jason@jason-Lenovo-H50-55:~$ ip a | awk ‘/inet /…

Read More

Some awesome tricks with awk, grep and sed.

Reading a large text file and then finding all words that contain between 5 and 7 vowels. Notice I am not using cat. jason@Yog-Sothoth:~/Documents$ egrep ‘^([^aieou]*[aieou]){5,7}[^aieou]*$’ < pg768.txt | wc -l 284jason@Yog-Sothoth:~/Documents$ egrep ‘^([^aieou]*[aieou]){5,7}[^aieou]*$’ < pg768.txt | wc -l 284 Count the number of times a single word appears in…

Read More

Some interesting and useful Linux commands and BASH tricks.

A useful awk implementation to count the number of entries in the /etc/passwd file. john@deusexmachina:~$ sudo awk -F: ‘{ print $1 }’ /etc/passwd | wc -l 34john@deusexmachina:~$ sudo awk -F: ‘{ print $1 }’ /etc/passwd | wc -l 34 And the quintessential “Hello World” in Awk. john@deusexmachina:~$ awk ‘BEGIN {…

Read More

How to search and replace text in a file with sed. Not using cat.

The sed command is very useful for searching and replacing text in a file. This is how to search for and replace a text string in a file. Homer@bejiitas ~ $ sed -i ‘s/&lt;main&gt;/&lt;mein&gt;/gi;’ my.cHomer@bejiitas ~ $ sed -i ‘s/&lt;main&gt;/&lt;mein&gt;/gi;’ my.c This is how to search and replace text in…

Read More