[comp.unix.questions] I'm learning UNIX and I have a simple question

jpope@hq.af.mil (i991x) (06/20/91)

    I have been recently moved to a new job that requires me to learn UNIX.  I
have a moderate programming background and I have worked on DOS in the past.  
One of the things I am currently learning is "pipes" and "redirected output."
In the UNIX that I use there is a command "who" which lists the users that
are currently on the system (as well as which terminal, when they logged on,
etc..).  The problem is that they are listed one user per line.
I would like to strip off the first field (the id-name) and output to the
screen four columns (four users per line instead of one) without the other
information about where and when they logged in.
     If there is an easy way to do this, please let me know.  If it entails a 
certain command, please give a brief explanation about it (again, I'm new to
UNIX and I am not aware of plethora of commands at my disposal).  Please E-mail
to me (posting will also be acceptable, after all, beggars can't be choosers).

mjo@irie.ais.org (Mike O'Connor) (06/20/91)

In article <jpope.677361841@sysp1> jpope@hq.af.mil (i991x) writes:

:I would like to strip off the first field (the id-name) and output to the
:screen four columns (four users per line instead of one) without the other
:information about where and when they logged in.

The "users" command sounds like what you'd need.  Not sure if it's
found in all Unixes, or a commad found in the BSD Unixes I generally
use.  It outputs the usernames all on one line, but it's entirely
possible to format the output any ol' way you want with tools like
cut, tr, awk/sed/perl, etc.





====
Mike O'Connor (mjo@ais.org)

les@chinet.chi.il.us (Leslie Mikesell) (06/20/91)

In article <jpope.677361841@sysp1> jpope@hq.af.mil (i991x) writes:

>One of the things I am currently learning is "pipes" and "redirected output."
>In the UNIX that I use there is a command "who" which lists the users that
>are currently on the system (as well as which terminal, when they logged on,
>etc..).  The problem is that they are listed one user per line.
>I would like to strip off the first field (the id-name) and output to the
>screen four columns (four users per line instead of one) without the other
>information about where and when they logged in.

Recent sysV's have a -q option to just give names and a -n number option
to control how many names per line to show with the -q option.  But there
are any number of ways to manipulate the output from a program into
what you want to see, and you should learn at least a few of them. Awk,
sed and the shell itself are the most general, pr has some options for
columns and formatting.

/bin/sh or ksh 
who |
 (while read A B
 do
 echo $A
 done) | pr -t -4


Les Mikesell
  les@chinet.chi.il.us

gwyn@smoke.brl.mil (Doug Gwyn) (06/21/91)

In article <jpope.677361841@sysp1> jpope@hq.af.mil (i991x) writes:
>In the UNIX that I use there is a command "who" which lists the users that
>are currently on the system (as well as which terminal, when they logged on,
>etc..).  The problem is that they are listed one user per line.
>I would like to strip off the first field (the id-name) and output to the
>screen four columns (four users per line instead of one) without the other
>information about where and when they logged in.

	who | awk '{print $1}' | sort -u | 4

where "4" is one of several links ("2" through "6") to the same
executable shell script that I maintain in one of the command directories:

	exec pr -t -w80 -`basename $0` $*

You can of course substitute "pr -t -w80 -4" for "4" in the above pipeline,
if you'd rather do that than create the useful commands "2" through "6".

There are other variations, using other commands to do essentially the
same jobs.  The commands are described in the UNIX user reference manual
in section 1; on many implementations one can also print a copy of the
manual entry on-line via the "man" command, as in "man 1 sort".

This example of exploiting the UNIX user environment is prototypical.
The first half of Kernighan and Pike's "The UNIX Programming Environment"
does a good job of teaching how to devise these things for yourself.

exspes@gdr.bath.ac.uk (P E Smee) (06/21/91)

In article <jpope.677361841@sysp1> jpope@hq.af.mil (i991x) writes:
>
>    I have been recently moved to a new job that requires me to learn UNIX.  I
>have a moderate programming background and I have worked on DOS in the past.  
>One of the things I am currently learning is "pipes" and "redirected output."
>...

I'd *strongly* recommend that you go out and buy a copy of Kernighan
and Pike's book, 'The Unix Programming Environment'.  Read it starting
at the front (don't be tempted to use it as a ref until after you've
read it).  Work out all the examples.  By the time you hit the middle
of the book, you'll be able to answer questions like this, rather than
asking them.  As I recall (been a long time) it took me about an hour
or two per chapter, including doing the exercises and thinking about
why they worked.

(Posted because I think this is good general advice.  If I can get thru
to .mil, I'll try to email some specific hints.)

-- 
Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK
 P.Smee@bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132

jrw@mtune.att.com (Jim Webb) (06/21/91)

In article <16470@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes:
>In article <jpope.677361841@sysp1> jpope@hq.af.mil (i991x) writes:
>>In the UNIX that I use there is a command "who" which lists the users that
>>are currently on the system (as well as which terminal, when they logged on,
>>etc..).  The problem is that they are listed one user per line.
>>I would like to strip off the first field (the id-name) and output to the
>>screen four columns (four users per line instead of one) without the other
>>information about where and when they logged in.
>
>	who | awk '{print $1}' | sort -u | 4
>
>where "4" is one of several links ("2" through "6") to the same
>executable shell script that I maintain in one of the command directories:
>
>	exec pr -t -w80 -`basename $0` $*

In the SVR3.2 and similiar universes, you can also say 'who -q -n4'

Jim

gwyn@smoke.brl.mil (Doug Gwyn) (06/22/91)

In article <1991Jun21.144113.22326@mtune.att.com> jrw@mtune.att.com (Jim Webb) writes:
>In the SVR3.2 and similiar universes, you can also say 'who -q -n4'

Yeah, but that sort of thing is problematic.  Different utilities have
different options to accomplish the same kind of effect (in this case,
formatting in multiple columns), when they have the options at all.
UNIX users should learn how to combine tools to accomplish these things;
it will make them more productive.

dkeisen@leland.Stanford.EDU (Dave Eisen) (06/23/91)

>In <1991Jun21.144113.22326@mtune.att.com> jrw@mtune.att.com (Jim Webb) writes:
>>In the SVR3.2 and similiar universes, you can also say 'who -q -n4'

Doug Gwyn replies:
>Yeah, but that sort of thing is problematic.  Different utilities have
>different options to accomplish the same kind of effect (in this case,
>formatting in multiple columns), when they have the options at all.

And besides, what does who have to do with formatting anyway? 

If I were writing who, it would never occur to me to add options to handle 
formatting. I would just worry about getting the user the information e
requested in a flexible format and have em take care of formatting it.

I'm not a mind reader. How should I know what a given user wants eir
output to look like?

gwyn@smoke.brl.mil (Doug Gwyn) (06/23/91)

In article <1991Jun22.195705.3287@leland.Stanford.EDU> dkeisen@leland.Stanford.EDU (Dave Eisen) writes:
>And besides, what does who have to do with formatting anyway? 

Yes, that's a proper designer's perspective.  The user, though, is
normally just as happy to use the extra option as to use any other
solution.  Around here we find a lot of one-line shell scripts in
people's personal command directories, often supplied to them by
somebody else, none of which know how the command actually works.

dkeisen@leland.Stanford.EDU (Dave Eisen) (06/23/91)

In article <16503@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes:
>In article <1991Jun22.195705.3287@leland.Stanford.EDU> dkeisen@leland.Stanford.EDU (Dave Eisen) writes:
>>And besides, what does who have to do with formatting anyway? 
>
>Yes, that's a proper designer's perspective.  The user, though, is
>normally just as happy to use the extra option as to use any other
>solution.

I agree with you Doug, but how is anyone supposed to remember that who 
happens to have this -n4 option? I program on a UNIX system every day of 
my life and I had no idea that who has this option. There is no way an 
occasional, casual user of UNIX would know it.

It would be one thing if UNIX commands used options consistently and
*all* commands used -n to indicate number of columns of output, but 
with the current mish-mash of command line options for different programs,
I don't see that adding a -n option to who gives a user anything.

It is much easier to associate pr with whatever (admittedly, relatively 
simple) formatting you want done than it is to try to remember the -n4 
option to who and the -q4 option to foo and the -w4 option to bar.

fyl@ssc.UUCP (Phil Hughes) (06/26/91)

A long list of people have complained about inconsistent use of options
on the UNIX system.  Which I must agree with.  But here is some real-world
comparison information.

First, my history.  I work for SSC.  We publish a series of pocket-sized
books on UNIX and such.  In particular we publish a command summary for
various versions of UNIX.  Each book contains a list of the commands, a
one-line description and a description of all the options and arguments.
We also publish a similar summary for MS-DOS.

I have just finished updating the MS-DOS summary to version 5.  Previously
I updated the UNIX summary to V.4.  Historically, we have been publishing
these suckers since 1983.

If I didn't know the history of MS-DOS and UNIX I would expect that UNIX was
developed by one company and MS-DOS had evolved over the last 20 years.
As each new version of UNIX has been introduced, commands have been modified
to make arguments and options more consistent.  On the other hand, MS-DOS
commands have an amazing assortment of options.

As an example, I mention the emm386.sys command that goes in config.sys
for MS-DOS.  There are three ways to set the page frame address.  One
consists of a key letter followed by a number, the second is the word frame
followed by an equal sign and the third is /p followed by an address.

This is not to say that UNIX is perfect but the trend seems to be toward
consistency in UNIX and toward anarchy in MS-DOS.  At the moment I can
survive better without my UNIX Command Summary than without my MS-DOS
Reference Card.


-- 
Phil Hughes, SSC, Inc. P.O. Box 55549, Seattle, WA 98155  (206)FOR-UNIX
     uunet!pilchuck!ssc!fyl or fyl@ssc.wa.com            (206)527-3385