From owner-freebsd-questions@FreeBSD.ORG Thu Feb 2 10:29:32 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E40D106564A for ; Thu, 2 Feb 2012 10:29:32 +0000 (UTC) (envelope-from nvass@gmx.com) Received: from mailout-eu.gmx.com (mailout-eu.gmx.com [213.165.64.42]) by mx1.freebsd.org (Postfix) with SMTP id E29CF8FC12 for ; Thu, 2 Feb 2012 10:29:31 +0000 (UTC) Received: (qmail invoked by alias); 02 Feb 2012 10:29:30 -0000 Received: from 77.49.192.186.dsl.dyn.forthnet.gr (EHLO [192.168.1.64]) [77.49.192.186] by mail.gmx.com (mp-eu006) with SMTP; 02 Feb 2012 11:29:30 +0100 X-Authenticated: #46156728 X-Provags-ID: V01U2FsdGVkX1/xoporcUrxVkCzuiBstgCe7XhXL6RbEjzqdIdQgM 1XktunxJSzrUDp Message-ID: <4F2A6575.90706@gmx.com> Date: Thu, 02 Feb 2012 12:29:09 +0200 From: Nikos Vassiliadis User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Matthias Apitz References: <20120202062236.GA3419@tinyCurrent> In-Reply-To: <20120202062236.GA3419@tinyCurrent> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 Cc: freebsd-questions@freebsd.org Subject: Re: some kind of binary sed(1) command X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2012 10:29:32 -0000 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