From: Hongyi Zhao on
Hi all,

I want to a insert some stuff as a new line after the line matching
regexp. Any hints?
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Hongyi Zhao on
On Sun, 21 Mar 2010 09:16:53 +0100, Janis Papanagnou
<janis_papanagnou(a)hotmail.com> wrote:

>> I want to a insert some stuff as a new line after the line matching
>> regexp. Any hints?
>
> awk '{print} /regexp/{print "some stuff"}'

Thanks a lot. After careful consideration, my requirement should be
described as follows:

1- If "some stuff" already exits immediately after the line matching
regexp, do nothing.

2- If "some stuff" already exits in other locations, move it to
desired location, i.e., immediately after the line matching regexp.

3- If "some stuff" doesn't exit, insert it immediately after the line
matching regexp.

Best regards.
--
..: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
From: Will Renkel on
hongyi.zhao(a)gmail.com wrote:
>Hi all,
>
>I want to a insert some stuff as a new line after the line matching
>regexp. Any hints?
>--
>.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.

using sed ....
sed '/chars to select line/a NEW LINE' filename

this puts in on std out
if want to change file itself

sed -i '/chars to select line/a NEW LINE' filename

--
---------------------------------------------------------------
Will Renkel
Wheaton, Ill.

---------------------------------------------------------------
From: Sidney Lambe on
On comp.unix.shell, Christian Brabandt <cb-news(a)256bit.org> wrote:
> On 2010-03-21, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote:
>> I want to a insert some stuff as a new line after the line matching
>> regexp. Any hints?
>
> Use sed:
>
> #v+
> chrisbra(a)256bit:~$ echo -e "foobar\none\ntwo" |sed -e '/foobar/a\
> > baz
> > '
> foobar
> baz
> one
> two
> #v-
>
> regards,
> Christian


sed -i '/regex/a line one\
line two ' file


Sid
From: Sidney Lambe on
On comp.unix.shell, Stephane CHAZELAS <stephane_chazelas(a)yahoo.fr> wrote:
> 2010-03-21, 18:44(+01), Sidney Lambe:
>> On comp.unix.shell, Christian Brabandt <cb-news(a)256bit.org> wrote:
> [...]
>>> chrisbra(a)256bit:~$ echo -e "foobar\none\ntwo" |sed -e '/foobar/a\
>>> > baz
>>> > '
>>> foobar
>>> baz
>>> one
>>> two
> [...]
>> sed -i '/regex/a line one\
>> line two ' file
> [...]
>
>
> Would have been OK in comp.gnu.shell. It's OK in
> comp.unix.shell, as long as you also mention that "-i" and
> having something following the "a" command are non-standard
> extensions recognised only by a some versions of a few sed
> implementations.
>
> Christian's sed command is the standard way to write it. However,
> his echo command is non standard (but would have been OK in
> comp.gnu.shell)
>
> --
> Stéphane

Okay. Thanks. How about if I include: GNU sed version 4.1.5?

How about /bin/echo for Christian's script?

Or /bin/printf?


Sid