On Fri, Apr 21, 2000 at 08:11:02PM +0200, jdd wrote:
> As one may think the solution is with emacs. For example, in emacs,
> 
> M-x replace-string
>  !
> C-q C-j
> \protected_separator C-q C-j
> !
> 
> inserts a protected separator before the !. C-q C-j inserts a cr in the
> emacs field.

And in vi you type 

        :% s/!/^M\\protected_seperator^M!/g

where ^M is created by typing Ctrl-V Ctrl-M

> 
> if any body nows how to do the same with sed or awks, I would appreciate
> (to write scripts)

With sed do:

sed 's/!/\
\\protected_seperator\
\!/g'

and make sure the carriage return comes immediately after the \ on each line or it 
won't work.

With Gawk (lovely tool!) you could do it this way

------------cut here------------
{ COUNT = split($0, LINE, "!")
  FIELD = 2
  print LINE[1]
  while (COUNT > 1) {
    printf "%s\n!%s\n","\\protected_seperator",LINE[FIELD]
    ++FIELD
    --COUNT
  }
}
------------cut here------------

The solution would be more elegant if you could be sure that each line would
have no more than one exclamation mark, but this does lines with any number
of them.  I did this with gawk but it should run in any awk.

-- 
Bruce

Those of you who think you know everything are annoying to those of us who
do.

Reply via email to