Marco,

The following works fine, it will replace your old file with a new one 
including the line duplication you are looking for.

cat filename | awk '{
        if (NF==1 && $1=="test") {
                print $0
                printf("%s","test1\n");
        }
        else {
                print $0
        }
}'>filename

Regards,

Ziad



>From: Mitchell Wright <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: <[EMAIL PROTECTED]>
>Subject: Re: Replace a line... with 2 lines
>Date: Sun, 06 Oct 2002 09:23:44 -0400
>
>I think you can do it with sed, but one trick would be to make sure you are
>not writing out to the same file as you are reading from. This may be 
>unique
>to me, but I had a hell of a time trying to figure what was wrong with a
>similar thing I was working on. It turned out to be that I had to bring in
>one file, do the operation, write out to another file and then change the
>name back to the original.
>
>Anyways... Give this a try:
>
>#cat filename | sed s/Test/Test\nTest1/g > filename2
>
>That works for me... ymmv :-)
>
>Mitchell
>
>On 10/6/02 8:46 AM, "Shaw, Marco" <[EMAIL PROTECTED]> wrote:
>
> > How can I do the following...
> >
> > A file something like this:
> >
> > <some lines>
> > Test
> > <some lines>
> >
> > I want to end up with:
> >
> > <some lines>
> > Test
> > Test1
> > <some lines>
> >
> > So basically, I want to replace "Test" with "Test<new line>Test1".  
>Can't seem
> > to do it with sed, and would prefer to stay away from Perl.  It won't
> > necessarily be on the same line number all the time either.
> >
> > I could possibly read the entire file in:
> >
> > While read line
> > Do
> > if [ "$line" = "Test" ]
> > then {
> > echo
> > echo "Test1"
> > }
> > fi
> > Done < ${FILE} > ${FILE}.tmp
> >
> > Which I just thought of, but didn't try, since it seems "ugly".
> >
> > Marco
> >
> >
>
>
>
>--
>redhat-list mailing list
>unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
>https://listman.redhat.com/mailman/listinfo/redhat-list




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to