Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Feb 2012 12:29:09 +0200
From:      Nikos Vassiliadis <nvass@gmx.com>
To:        Matthias Apitz <guru@unixarea.de>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: some kind of binary sed(1) command
Message-ID:  <4F2A6575.90706@gmx.com>
In-Reply-To: <20120202062236.GA3419@tinyCurrent>
References:  <20120202062236.GA3419@tinyCurrent>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2/2/2012 8:22 AM, Matthias Apitz wrote:
>
> Hello,
>
> I have a normal ASCII file wich has in some places two lines of '*',
> separated by an empty line, i.e.
>
> ....\n
> *********************\n
> \n
> *********************\n
> ....\n
>
> and I want to substitute the \n between the star lines by \f; the
> 'binary' sed command would just be
>
> 	s/*****\n\n*****/*****\n\f*****/
>
> which ofc does not work with sed(1) because it is line oriented;
> I could write something in perl, C, awk or whatever language, but I
> would prefer to do it with the normal commands... any ideas?
>
> Thanks
>
> 	matthias

Perhaps, something like this:
> raidmadi% sed '/\*\*\*\*/{ N;N;s/\(\*\*\*\*\n\)\(\n\)\(\*\*\*\*\)/\1\\f\
> \3/; }; '
> ****
>
> ****
> ****
> \f
> ****
> ****
> foo
> ****
> ****
> foo
> ****

Keep in mind that I am using zsh which allows you to write multi-line
commands.

HTH, Nikos



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4F2A6575.90706>