Solved

How to get column width sizes of Linux commands

Posted on 2015-02-15
4
207 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
Comment Utility
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
Comment Utility
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
Comment Utility
the cut command and the sed command produce different results with the output from my finger
0
 

Author Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now