Solved

How to get column width sizes of Linux commands

Posted on 2015-02-15
4
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

691 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