University Crest

[wlug] Command line util of the day.

 
wlug archive index About the wlug list Mailing lists home
To The University of Waikato HomepageWaikato Home > Waikato Mailing Lists > wlug Info > wlug archives
Perry Lorier perry@c...
Tue Apr 19 23:00:17 NZST 2005


Oliver Jones wrote:
> To continue the trend set by James Clark...  Here is my choice for
> useful command-line tool of the day.
> 
> fold

Ooh, my favourite is "join(1)"[1]  with a bit of join(1), cut(1),
grep(1) you can do basic rdbms queries on text files.  The thing to
remember about join is it requires both input files to be sorted on the key.

an example join command:

w | awk '{print $1}' | sort | join -j 1 -t: -o 2.5 - <(getent passwd |
sort)

to break this down
 w |
List the currently logged in users and pipe its output to:
 awk '{print $1}' |
awk then for each line of the file prints the first column (getting rid
of the other random junk w has) and pipes its output to:
 sort |
Both import files must be sorted, so we sort the input.  yay.  This gets
piped to the join.  The join also reads from a named pipe (thats what
the <() is about) consisting of:
 getent passwd | sort
List everyone in the passwd database and sort it (everyone is in ldap
here, so the usual sort /etc/passwd doesn't work)

The join command then joins on field 1 on both files (-j 1), considering
fields to be separated by :'s (-t :), and outputting column 5 from file
2 (-o 2.5), and reading from standard in (our post processed w pipeline)
and from the other passwd file parsing pipeline.

So the net result of this command is that it lists the gecos information
(real name etc) of all the users currently logged in, a bit long winded,
but useful on multiuser machines where you don't directly know who that
random person is that's running ./memhog.

----
[1]: Which nobody uses.




More information about the wlug mailing list
NOTICE: This is an archive of a public mailing list. The University of Waikato is not responsible for its contents.

The University of Waikato - Te Whare Wananga o Waikato