Unix/OSX trick to parse column based console text to get specific row and column text value

With either OSX or *nix OS, console outputs have text data in columns. Sometimes it may required to parse column based console output to get specific row or column value.  In this article we will use a combination of sort, head, tail, tr, cut commands to get particular row or column value from console output.

Lets start with ls command which returns the folder and files name as shown below:

$ ls -l

total 8
drwxr-xr-x 2 avkash staff 68 Sep 17 00:10 Any
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Apps
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Books
drwxr-xr-x 2 avkash staff 68 Sep 17 00:08 Code
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Music
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Songs
drwxr-xr-x 2 avkash staff 68 Sep 17 00:08 Zeppos
-rw-r–r– 1 avkash staff 46 Sep 17 00:23 data.txt

$ ls -l | head -n 2 | tr -s ‘ ‘ | cut -d’ ‘ -f9

Any

$ ls -l | tail -n 1 | tr -s ‘ ‘ | cut -d’ ‘ -f9
data.txt

You can also use this trick with sorting command output using sort command (-n, -M, -d etc….)

$ ls -l | sort -n
-rw-r–r– 1 avkash staff 46 Sep 17 00:23 data.txt
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Apps
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Books
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Music
drwxr-xr-x 2 avkash staff 68 Sep 17 00:07 Songs
drwxr-xr-x 2 avkash staff 68 Sep 17 00:08 Code
drwxr-xr-x 2 avkash staff 68 Sep 17 00:08 Zeppos
drwxr-xr-x 2 avkash staff 68 Sep 17 00:10 Any
total 8

$ ls -l | sort -n | tail -n 2 | tr -s ‘ ‘ | cut -d’ ‘ -f9
Any

$ ls -l | sort -n | head -n 1 | tr -s ‘ ‘ | cut -d’ ‘ -f9
data.txt

This trick does works with any text in console i.e. you could use output of a file as well.

Example 2:

$ cat data.txt

Any
Apps
Books
Code
Gum
Music
Songs
Zeppos
X

$ cat data.txt  | tail -n 1 | tr -s ‘ ‘ | cut -d’ ‘ -f1

X

$ cat data.txt | head -n 1 | tr -s ‘ ‘ | cut -d’ ‘ -f1

Any

Thats all. Have fun!!

Thanks to my friend Aaron for showing this great trick.

Keywords: ls, sort, head, tail, tr, cut

 

Impact of appreciation and recognition in building a great team

team building2
Appreciation and Recognition are two key ingredients for building a great team. Team leaders can use appreciation and recognition to build a great team. Lets see what Appreciation and Recognition accounts in building a great team.
Appreciation:
  • Appreciation belongs to the personal attribute or personality
  • Appreciation means accepting who the person is as person
  • Appreciation means value your team member as person or individual first
  • A simple example is that if a team member makes mistake, ask him “how he or she feels?” or “ask him  or her that you are there to help”. Because when a person makes mistake he or she is still the same team member and at that time a few words of appreciation motivates him to not to make mistake again. Making him or her sure to not to commit mistake again will rarely work because you as leader can fix more problems by appreciating a person.
Recognition:
  • Recognition is something given for what a person does or achieve as individual
  • Recognition is given to assert that the work done by the team member, has value beyond his or her regular contribution
  • Recognition is given as an act of appreciation when someone went above and beyond, requires appreciation
  • Don’t hesitate to recognize achievements with team, because recognition hidden from the team is not recognition. it is just an act of appreciation.
The key difference between appreciation and recognition is that you appreciate the person and you recognize the act done by the person. All team members needs appreciation and recognition so give them when it is needed. Don’t hesitate to say a few words of appreciation in public because most of the time, few words or appreciation in public, create loyalty and boot team morale.
Finally Be Authentic:
  • Be authentic when appreciating and recognizing your team members individually. Don’t do it if you feel that you “have to” do it. Do it only because you feel someone really deserve it and you want to do it from your heart. Being original and authentic goes long way and creates your credibility in the team.
  • Once you prove to be authentic, you will create a team environment which is transparent for any discussion in need. The best things come by being authentic is that there are “no surprises”.