Parsing Outputs in terminal made super easy !

Hi all , People using linux operating system sometimes do shell scripting and often get confused with commands to parse text as there are many commands and utilities to do the same like sed , awk , tr , cut etc .

Today let me share with you an approach on parsing the outputs to get your desired value when you know the output format.


Let’s demonstrate it with an example :

command : last

output : will list the last login time for users

now let’s say i want to the only time when i logged in and nothing else .

Lets run the command :


output :

administrator@ubuntu:~$ last
administ pts/1 :0.0 Wed Nov 2 05:37 still logged in
reboot system boot 3.8.0-29-generic Wed Nov 2 05:29 – 06:22 (00:53)
reboot system boot 3.8.0-29-generic Tue Nov 1 05:41 – 05:42 (00:00)

wtmp begins Tue Nov 1 05:41:25 2016

Now we”ll use two commands cut to cut out desired columns and sed to cut out desired row. This way the user can view his out put as a table and get the desired entry he/she wants.

syntax : cut -d ” ” -f 3

# -d defines the delimiter and -f asks for the column number you want to extract according to the table defined by the delimiter

syntax : sed ‘x!d’

x is the number of row you want . as you have already got the desired column using this command with piping you can get the desired entry from the table



So final ultimate command :

last | cut -d ” ” -f 12 | sed ‘2!d’




Follow our Youtube Channel for tutorials on Ethical Hacking

Click here to visit our channel –> CHANNEL

#like #comment #share

Click here to visit our Facebook Page SECTOR443



Stay Safe Stay Secure | Sector443

Leave a Reply

Your email address will not be published. Required fields are marked *