From owner-freebsd-questions@FreeBSD.ORG Thu Feb 2 08:07:02 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 3238C106566B for ; Thu, 2 Feb 2012 08:07:02 +0000 (UTC) (envelope-from ftp51246-2575596@sh4-5.1blu.de) Received: from sh4-5.1blu.de (sh4-5.1blu.de [213.83.63.54]) by mx1.freebsd.org (Postfix) with ESMTP id B5D888FC0A for ; Thu, 2 Feb 2012 08:07:01 +0000 (UTC) Received: from ftp51246-2575596 by sh4-5.1blu.de with local (Exim 4.69) (envelope-from ) id 1Rsrh2-0002hD-VI; Thu, 02 Feb 2012 09:06:57 +0100 Date: Thu, 2 Feb 2012 09:06:56 +0100 From: Matthias Apitz To: Robert Bonomi Message-ID: <20120202080656.GA7403@sh4-5.1blu.de> References: <20120202062236.GA3419@tinyCurrent> <201202020751.q127puMO011247@mail.r-bonomi.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201202020751.q127puMO011247@mail.r-bonomi.com> X-Operating-System: FreeBSD 7.0-RELEASE (i386) User-Agent: Mutt/1.5.17+20080114 (2008-01-14) 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 Reply-To: Matthias Apitz List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2012 08:07:02 -0000 --DocE+STaALJfprDB Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit El día Thursday, February 02, 2012 a las 01:51:56AM -0600, Robert Bonomi escribió: > > From owner-freebsd-questions@freebsd.org Thu Feb 2 00:27:33 2012 > > Date: Thu, 2 Feb 2012 07:22:36 +0100 > > From: Matthias Apitz > > To: freebsd-questions@freebsd.org > > Subject: some kind of binary sed(1) command > > > > > > 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? > > > Use sed. > > > *GRIN* Thanks, but the attached script (based on your content and saved to a script file) just gives: $ sh sed sed: 5: " t l :l ...": invalid command code / Leaving your original mail as well here; Thanks again matthias > > > > > > As follows: > > sed -e ' t l > :l > /^[*]+$/ { > N > !/\n$/ { > P > s/^.*\n// > t l > } > /\n$/ { > N > !/\n\n[*]*$/ { > P > s/^.*\n// > P > s/^.*\n// > t l > } > /\n\n[*]*$/ s/\n\n/\n\f/ > } > }' > > Note: "how" this incantation works is left as an excercise for the student. > Careful perusal of the FM will provide enlightenment. > > Caveat: this will convert: > {stars} > {blank} > {stars} > {blank} > {stars} > > to; > {stars} > {formfeed} > {stars} > {blank} > {stars} > > not: > {stars} > {formfeed} > {stars} > {formfeed} > {stars} > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" -- Matthias Apitz t +49-89-61308 351 - f +49-89-61308 399 - m +49-170-4527211 e - w http://www.unixarea.de/ ¡Ya basta! ¡Imperialistas occidentales, quitad las manos de Libia! There's an end of it! Imperialists occidentals, hands off Libya! Schluss jetzt endlich! Imperialisten des Westens, Haende weg von Libyen! --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=sed #!/bin/sh sed -e ' t l :l /^[*]+$/ { N !/\n$/ { P s/^.*\n// t l } /\n$/ { N !/\n\n[*]*$/ { P s/^.*\n// P s/^.*\n// t l } /\n\n[*]*$/ s/\n\n/\n\f/ } }' --DocE+STaALJfprDB--