Solved

How to get column width sizes of Linux commands

Posted on 2015-02-15
4
215 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

809 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