Solved

How to get column width sizes of Linux commands

Posted on 2015-02-15
4
217 Views
Last Modified: 2015-02-17
I ran across this command the other day:

 % finger | grep -v ^Login | cut -b10-34 | sort -u
  Angela Glinos            
  Peng Yi                  
  ordinary user            
  xiaoyu gao               
  J. T. C. Chiu            
  Lok Wilson 

Open in new window


If I understand correctly, the cut -b option will select bytes 10-34 from the output of the finger command. I'm interested in knowing how can one determine the width of the columns in finger (size of bytes)?
0
Comment
Question by:TampaJay
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40611514
You're right, "-b" means bytes, "10-34" means the byte positions, starting from 1.

The output columns of "finger" are of fixed width, but since the non-blank content of most columns is of variable length and, moreover, some columns (even in the header) can/will consist of a variable number of words there is no easy way to programmatically determine the column widths.

Since it's a one-time effort I'd simply suggest running the "finger" command and counting (sic!) the characters.

You could redirect the output to a file ("finger > finger.out"), then edit this file with vi/vim. On the right bottom you'll see an indication of the current cursor position in the format "line,column". Use the "column" value to help counting.

The man pages of some commands describe the command output in detail, so you might find the column layout there. Unfortunately, finger's manpage does not have such a description, afaik.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 40611597
I'd use sed instead of cut

finger | sed 1d | sed -e "s/^[A-z]* *//" -e "s/  .*//"|sort -u
0
 
LVL 84

Expert Comment

by:ozo
ID: 40611723
the cut command and the sed command produce different results with the output from my finger
0
 

Author Comment

by:TampaJay
ID: 40614302
Thank you for the comments. I just ended up using awk to grab the column I needed.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question