[comp.unix.questions] Simple Question

schriste@uceng.UC.EDU (Steven V. Christensen) (12/02/89)

Excuse the simple question, but I have a bunch of shar files that
I want to unshar. Unfortunately all 20+ have the mail headers on them.
In SED, how would I pipe the files to remove everything before the
"#!/bin/sh" ? Also, how would I get everything between the "#!/bin/sh"
and the "exit 0" at the end (for those mailers which append a .sig)?

Thanks for your help,

		Steven

-- 
Steven V. Christensen
U.C. College of Eng.
schriste@uceng.uc.edu

jgreely@oz.cis.ohio-state.edu (J Greely) (12/02/89)

In article <3013@uceng.UC.EDU> schriste@uceng.UC.EDU
 (Steven V. Christensen) writes:
>Excuse the simple question, but I have a bunch of shar files that
>I want to unshar. Unfortunately all 20+ have the mail headers on them.
>In SED, how would I pipe the files to remove everything before the
>"#!/bin/sh" ?

Strictly speaking, you need to remove everthing before the first line
that begins with either "#" or ":", since many shar programs produce
the latter.

	sed -n '/^[#:]/,$ p'

is the command you're looking for.

> Also, how would I get everything between the "#!/bin/sh"
>and the "exit 0" at the end (for those mailers which append a .sig)?

You don't.  The "exit 0" is there specifically to prevent the shell
from reading the signature.


Of course, to beat a dead horse, you can do it in perl like this:
	perl -ne 'print if /^[#:]/..eof();'
-=-
J Greely (jgreely@cis.ohio-state.edu; osu-cis!jgreely)

tale@cs.rpi.edu (Dave Lawrence) (12/03/89)

In <JGREELY.89Dec2101808@oz.cis.ohio-state.edu> jgreely@oz.cis.ohio-state.edu
(J Greely) writes:
> Strictly speaking, you need to remove everthing before the first
> line that begins with either "#" or ":", since many shar programs
> produce the latter.  [...]  The "exit 0" is there specifically to
> prevent the shell from reading the signature.


>           sed -n '/^[#:]/,$ p'
>           perl -ne 'print if /^[#:]/..eof();'

Perl is overkill in this case since it is doing a job that both awk
and sed can do with less overhead.  A little script I tossed together
a long time ago to do the job uses the awk method:

================
#! /bin/sh
files=${*:--}
for file in $files; do
  /bin/awk '/^#! ?\/bin\/sh *$/,/^ *exit 0 *$/' $file | /bin/sh
done
================

I've been using this for a couple of years; I suppose I should modify
it to handle the ":" case too, since I've seen a few like that.

For more than one file, a single perl script to handle them all would
be most efficient.  For one file, sed is probably best.  All three of
them are pretty low overhead for this application, though, so I'm just
nitpicking. :-)  As is obvious by the above "unsh", I wasn't exactly
offering the most efficient way either.  Just another example to show
the interaction of Unix tools.

Dave
-- 
   (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))

mb@rex.cs.tulane.edu (Mark Benard) (12/12/89)

In article <3013@uceng.UC.EDU> schriste@uceng.UC.EDU (Steven V. Christensen) writes:
>Excuse the simple question, but I have a bunch of shar files that
>I want to unshar. Unfortunately all 20+ have the mail headers on them.
>In SED, how would I pipe the files to remove everything before the
>"#!/bin/sh" ? Also, how would I get everything between the "#!/bin/sh"
>and the "exit 0" at the end (for those mailers which append a .sig)?

Try using the unshar utility.  This is exactly what it was designed to
do.  It will strip the header and other leading junk and, if there is
an 'exit 0', it will also correctly strip the .signature.
-- 
Mark Benard
Department of Computer Science     INTERNET & BITNET: mb@cs.tulane.edu
Tulane University                  USENET:   rex!mb
New Orleans, LA 70118

thssdwv@iitmax.iit.edu (David William Vrona) (02/10/91)

Can a user belong to more than one group?  If so, how does the user change
from one group to the other?

Thanks 
-- 
##############################################################################
#  I was gonna run up on ya and do a  #  David W. Vrona                      #
#  Rambo.... O.J. Jones               #  Illinois Institute of Technology    #
##############################################################################
#  Internet:  thssdwv@iitmax.iit.edu  #  UUCP:                               #
##############################################################################

guy@auspex.auspex.com (Guy Harris) (02/11/91)

>There are also various hybrid systems that implement both methods.

I presume Doug is referring here to the fact that some systems let a
process be in more than one group (the limit in many systems is larger
than 8; it's 16 in 4.3BSD and many other systems, and may be
(configurably?) higher than 16 in S5R4), but don't always assign a
newly-created file the group ID of the parent directory.  The model used
in SunOS 4.x (unless a file system is mounted with the "always use the
parent directory") flag, and in S5R4, is that if the parent directory
doesn't have the set-GID bit set, the GID is the effective group ID, and
if it has that bit set, it's the GID of the parent directory.

(Those systems may also have a "newgrp" command to let you set the
effective group ID.)