A possible solution for the onlyshell.pl
program is as follows:
#! /usr/bin/perl # onlyshell.pl - read from "psout", print first line, and only lines # which represent shell processes. A shell is a process in which # the COMMAND field (last field in "ps" output) is a # "csh" or "bash", which has a minus sign before it: # # kjacks 21255 Sep30 0:00 -bash # # but not: # # kjacks 24536 11:47 0:00 bash use warnings; use strict; my $filename = 'psout'; # open $filename for reading # read first line and print it my $line = <PS>; # read remaining lines and print only those which match the shell pattern while (<PS>) { if ( m/\s-(bash|csh)$/ ); } # close the file close PS;