From owner-freebsd-questions  Fri Mar 10  7:27:22 2000
Delivered-To: freebsd-questions@freebsd.org
Received: from av1.mottmac.com (av1.mottmac.com [138.104.176.4])
	by hub.freebsd.org (Postfix) with ESMTP id 21D8D37BA13
	for <freebsd-questions@freebsd.org>; Fri, 10 Mar 2000 07:27:15 -0800 (PST)
	(envelope-from JW1@mm-croy.mottmac.com)
Received: from smtp-gate.mottmac.com (smtp-gate.mottmac.com) by av1.mottmac.com
 (Content Technologies SMTPRS 2.0.15) with ESMTP id <B0001670037@av1.mottmac.com> for <freebsd-questions@FreeBSD.org>;
 Fri, 10 Mar 2000 15:30:11 +0000
Message-Id: <934E0337010C01E0@smtp-gate.mottmac.com>
X-SMF-Message-ID: 934E0337010C01E0
X-SMF-Hop-Count: 2
Date: Fri, 10 Mar 2000 15:26:00 +0000
From: Jonathan Wall <JW1@mm-croy.mottmac.com>
To: freebsd-questions@FreeBSD.org
X-EXP32-SerialNo: 50000077
Subject: truncating lines with a script...
MIME-Version: 1.0
X-Mailer: InterChange (Hydra) SMTP v3.51
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
Sender: owner-freebsd-questions@FreeBSD.ORG
Precedence: bulk
X-Loop: FreeBSD.ORG

Hi there,

Hopefully somebody can spare a moment to solve a problem I'm having...

I have a very simple sh script that runs 'ps' via rsh for some machines on 
our network and then pipes the output through grep to pick out the lines of 
interest - in this case the Xvnc processes.  I would like to then pipe the 
output through another command to remove the superfluous Xvnc command line 
switches the ps command also shows.

The script as it currently stands is shown below.  I thought sed would be 
the answer but apart from having an astoundingly cryptic man page, I think 
it can only delete whole lines containing a particular string rather than a 
segment of a line.  I know I could have used 'comm' instead of 'command' in 
the script to have a shortened output from ps, but then I can't see which 
screen the Xvnc processes are attached to.  The typical output is below the 
script and given this example I would ideally like to remove everything 
after the ':1'.  Perhaps I should be using awk or perl ???

I'm frustrated to be unable to work this out for myself since it seems so 
trivial.  Is there a correspondingly trivial solution ??

	Thanks in advance to anyone who has time to write a reply,

		Jonathan Wall.

### My script ###

#!/bin/sh
echo ""
echo ""
echo "--------------------------------------------------------------"
echo "      cfd1"
echo "--------------------------------------------------------------"
rsh cfd1 ps -e -o 
user,pid,pcpu,pmem,vsize,rssize,tty,state,start,cputime,etime,command \
| grep -w -e USER -e Xvnc \
| grep -v -e grep
echo "--------------------------------------------------------------"
echo "      cfd2"
echo "--------------------------------------------------------------"
rsh cfd2 ps -e -o 
user,pid,pcpu,pmem,vsize,rssize,tty,state,start,cputime,etime,command \
| grep -w -e USER -e Xvnc \
| grep -v -e grep
echo "--------------------------------------------------------------"
echo "      cfd3"
echo "--------------------------------------------------------------"
rsh cfd3 ps -e -o 
user,pid,pcpu,pmem,vsize,rssize,tty,state,start,cputime,etime,command \
| grep -w -e USER -e Xvnc \
| grep -v -e grep
echo ""
echo ""


### Typical output ### (apologies if the long line causes problems for your 
email client)

--------------------------------------------------------------
      cfd1
--------------------------------------------------------------
USER        PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME     
ELAPSED COMMAND
jw1        2515  0.0  0.5 7.68M 3.7M ttyp4    S    18:43:20     0:00.58
  1:27 Xvnc :1 -desktop X -httpd /usr/personal/jw1/apps/share/vnc/classes 
-auth /usr/personal/jw1/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 
120000 -rfbauth /usr/personal/jw1/.vnc/passwd -rfbport 5901 -fp 
/usr/lib/X11/fonts/misc/,/usr/lib/X11/fonts/75dpi/,/usr/lib/X11/fonts/100dpi
/,/usr/lib/X11/fonts/decwin/75dpi/,/usr/lib/X11/fonts/decwin/100dpi/,/usr/li
b/X11/fonts/cde/75dpi/,/usr/lib/X11/fonts/cde/100dpi/,/usr/lib/X11/fonts/use
r/75dpi/,/usr/lib/X11/fonts/user/100dpi/,/usr/lib/X11/fonts/user/misc/,/usr/
lib/X11/fonts/Speedo/,/usr/lib/X11/fonts/Type1/,/usr/lib/X11/fonts/Type1Adob
e/
--------------------------------------------------------------
      cfd2
--------------------------------------------------------------
USER        PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME     
ELAPSED COMMAND
--------------------------------------------------------------
      cfd3
--------------------------------------------------------------
USER        PID %CPU %MEM   VSZ  RSS TTY      S    STARTED         TIME     
ELAPSED COMMAND






To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message