[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Sed replace and add a line



"Christopher W. Aiken" wrote:
> 
> On Thu, Aug 31, 2000 at 12:13:33PM +0000, Jaume Teixi wrote:
> -|I'm trying to use sed to search pattern 228 and add a line as follows:
> -|
> -|288
> -|229
> -|
> -|I type:
> -|sed /s/228/'\n 229`/

My copy of sed complains when I type in the pattern you have supplied. 
The leading slash is "extra" and you have one each of a single quote and
a backquote.  So I'm assuming you wanted to use the substitute
instruction to somehow "replace" 228 with 228<NL>229.

Try this:

   $ sed 's/228/228
   > 229/' ...

The newline you type between the 228 and 229 is "embedded" in the
pattern, because of the single quotes surrounding the substitute
instruction.  Also you must include 228 in the replacement part of the
substitute to get it back.

There are ways to tell sed to insert/append lines that will work also:

   $ sed '/228/a\
   > 229' ...

The initial /228/ is used as an address to locate the line to append
after.  Each line to insert/append (there can be more than one) must end
in a backslash, EXCEPT for the last line.  The 'a' appends after the
current line, the 'i' inserts before the current line.

> 
> Try changing the "\n" to a "Ctrl-V Ctrl-M"
> 

This will not produce the desired appearance.  Control-M is a carriage
return.  The result (once the substitute is fixed: s/228/228^M229/) is
to print the 228, a return (minus the linefeed), then 229, which results
in overprinting the 228.

-- 
Bob McGowan
Staff Software Quality Engineer
VERITAS Software
rmcgowan@veritas.com



Reply to: