Solved

How to get column width sizes of Linux commands

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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