[comp.unix.questions] History substitution

MMKOISTINEN@uku.fi (MIKA KOISTINEN (PHONE 971-311796)) (03/02/90)

Hello,

	My problem is how to replace all occurances of substring 
in history substitution. (In csh)

for example

	echo aaaaaaaaa
        !:gs/a/b
i get
	echo baaaaaaaa

	echo aa ab aaaa
	!:gs/a/b
	echo ba bb baaa
What's wrong ?

<.mika>
 Mika Koistinen    * Kraftwerk   : I program my home computer
 Myll{rintie 57F62 * Dire Straits: That ain't working thats the way you do it
 70780 KUOPIO      * funet: kylk36::mmkoistinen  BITNET: MMKOISTI@FINKUO
 FINLAND           * internet: mmkoistinen@uku.fi 

mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) (03/06/90)

Mika,

	One way to do this is to pipe the command thru sed like so:
!! | sed "s/a/b/g"

...Mike Chinni
   <mchinni@pica.army.mil>

chris@mimsy.umd.edu (Chris Torek) (03/07/90)

In article <22613@adm.BRL.MIL> MMKOISTINEN@uku.fi
(MIKA KOISTINEN (PHONE 971-311796)) writes:
>	echo aa ab aaaa
>	!:gs/a/b
>	echo ba bb baaa
>What's wrong ?

The C shell documentation says:

          s/l/r/ Substitute l for r

and

          g      Apply the change globally, prefixing the above, e.g. `g&'.

What it does not say is that `g' means `apply the change to every *word*',
rather than `to every instance of ``l'' in every word'.  The C shell will
only substitute once in each argv[] element.  (It quietly implies this with
the sentence:

     Unless preceded by a `g' the modification is applied only to
     the first modifiable word.  With substitutions, it is an
     error for no word to be applicable.

In other words, everything is based on words, not on characters.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris