[comp.unix.questions] Sed question

jhc@vax5.CIT.CORNELL.EDU (01/27/89)

Hello.

Our implementation of the news software, because it is run in Eunice on top
of VAX/VMS, has some shortcomings.  One of these, is that, when using Pnews
or Rnmail, the Reply-To: line does not include your real name, just a pair
of parenthesis.  I would like to add a line to my personalised copies of
Pnews and Rnmail to automate adding in the realname info.  Unfortunately,
I'm having difficulty getting the sed line correct.  Specifically, I want
sed to find the line that starts Reply-To: and then replace any instances of
() with ($REALNAME) where $REALNAME is the value of the environmental
variable REALNAME, and where the parenthesis are in the file.  Perhaps it
would be more understandable liek this:
what we have:	\050\051
what we want:	\050($REALNAME)\051
where: \nnn is the character specified by nnn ascii, nnn in octal
and:   ($CCC) is the value of the env. variable named CCC.

As an alternative, I would accept having a specific string inserted between
the parenthesis on the Reply-To: line rather than the value of the env.
variable.

Is this possible?

Thanks in advance for any help in this.

P.S.	Pnews & Rnamil are written in sh, for those unfamiliar w/ those 2
	scripts.

-JimC
--
James H. Cloos, Jr.          "Entropy isn't what it used to be."
jhc@Crnlvax5.BITNET            --c/o Fortune @ batcomputer.UUCP
jhc@Vax5.CIT.Cornell.EDU	 #include <std_disclaimers.h>
cornell!vax1!vax5.cit.cornell.edu!jhc@rochester.UUCP
B-7 Upson Hall, Cornell Univ., Ithaca, NY 14853   +1 607 272 4519

leo@philmds.UUCP (Leo de Wit) (01/28/89)

In article <17810@vax5.CIT.CORNELL.EDU> jhc@Vax5.CIT.Cornell.EDU (James H. Cloos, Jr.) writes:
   []
|I'm having difficulty getting the sed line correct.  Specifically, I want
|sed to find the line that starts Reply-To: and then replace any instances of
|() with ($REALNAME) where $REALNAME is the value of the environmental
|variable REALNAME, and where the parenthesis are in the file.
   []

sed '/^Reply-To:/s/()/('$REALNAME')/g' your_file

Since the $REALNAME is outside quotes, it is expanded by the shell.

    Leo.

leo@philmds.UUCP (Leo de Wit) (01/28/89)

In article <938@philmds.UUCP> leo@philmds.UUCP (Leo de Wit) writes:
|sed '/^Reply-To:/s/()/('$REALNAME')/g' your_file

Sorry, I was too fast. This fails if $REALNAME contains spaces. Better
do it like this (assuming you're using a Bourne shell):

sed "/^Reply-To:/s/()/($REALNAME)/g" your_file

    Leo.

merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) (01/30/89)

In article <938@philmds.UUCP>, leo@philmds (Leo de Wit) writes:
| sed '/^Reply-To:/s/()/('$REALNAME')/g' your_file
| 
| Since the $REALNAME is outside quotes, it is expanded by the shell.

Including the spaces.  This will break for REALNAME="Randal L. Schwartz".
Try instead:

  sed "/^Reply-To:/s!()!(${REALNAME-$USER})!g" your_file

where "!" should probably be replaced with a control-G or some other
very very unlikely character in REALNAME for safety.

Enjoy.
-- 
Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095
on contract to BiiN (for now :-), Hillsboro, Oregon, USA.
ARPA: <@iwarp.intel.com:merlyn@intelob.intel.com> (fastest!)
MX-Internet: <merlyn@intelob.intel.com> UUCP: ...[!uunet]!tektronix!biin!merlyn
Standard disclaimer: I *am* my employer!
Cute quote: "Welcome to Oregon... home of the California Raisins!"

leo@philmds.UUCP (Leo de Wit) (01/31/89)

In article <4094@omepd.UUCP> merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) writes:
|In article <938@philmds.UUCP>, leo@philmds (Leo de Wit) writes:
|| sed '/^Reply-To:/s/()/('$REALNAME')/g' your_file
|| 
|| Since the $REALNAME is outside quotes, it is expanded by the shell.
|
|Including the spaces.  This will break for REALNAME="Randal L. Schwartz".
|Try instead:
|
|  sed "/^Reply-To:/s!()!(${REALNAME-$USER})!g" your_file
|
|where "!" should probably be replaced with a control-G or some other
|very very unlikely character in REALNAME for safety.

If you had taken the trouble to read my own follow-up (sent out 5 min.
later, where I use the " quoting too), this reply hadn't been
necessary. You were probably as hasty to reply to my article as I
was to get it out 8-). Perhaps I'd better cancelled the first message ...

		Leo.

smaxwell@hpcuhc.HP.COM (Susan Maxwell) (04/11/89)

Got a sed question for you:  I'm creating a sed filter to mask out and
delete unwanted characters in a trace file.  I'm having trouble with this
configuration:

        LINE I:    PROMPT>
        LINE I+1:  >
        LINE I+2:  <

Whenever I see this series, I want to delete ALL THREE lines.  I can't
create a pattern /PROMPT\>\\n\>\\n\</d   as far as I can tell, because
sed won't allow patterns to span lines.  Is there a way to do this, without
resorting to awk or ed?   

Susan Maxwell

maart@cs.vu.nl (Maarten Litmaath) (04/13/89)

smaxwell@hpcuhc.HP.COM (Susan Maxwell) writes:
\        LINE I:    PROMPT>
\        LINE I+1:  >
\        LINE I+2:  <

\Whenever I see this series, I want to delete ALL THREE lines.

sed -n '
	/^PROMPT>$/{
		h
		n
		H
		/^>$/{
			n
			/^<$/b
			H
		}
		g
	}
	p
'
-- 
 "If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam:
  it's probably wrong." (jim@bilpin). |maart@cs.vu.nl, mcvax!botter!maart

steinbac@hpl-opus.hpl.hp.com (Guenter Steinbach) (11/30/90)

In comp.unix.questions, bm@bike2work.Eng.Sun.COM (Bill Michel) writes:

> All I want to do is match the first word (all caps) on each line.
> My input looks like

>  Shortname            
>  --------------------
>  IPCINSTALL         
>  DESKSET           
>  SS2INSTALL       

> and I'm trying sed -n '/^ *[A-Z0-9]*/p' without success (the output is 
> exactly the same as the input). 

That is because * matches 0 or more occurrences.  So you are in effect
asking for "first 0 or more blanks, then 0 or more capital letters" -
that is all lines, regardless of content, since you don't specify what
comes after those two.

Try this:
sed -n '/^ *[A-Z0-9][A-Z0-9]* *$/p'
            ^^^^^^^^         ^ ^
At least one capital         | |
latter.                      | |
                             | |
The lines in your posting have |
trailing blanks.  Put the blank|
inside the brackets if you     |
want to match multiple capital |
words.                         |
                               |
This prevents matching lines with anything but capitals, numbers, and
blanks.

Good luck!

	 Guenter Steinbach		gunter_steinbach@hplabs.hp.com