X-Spam-Check-By: sourceware.org
From: "fergus" <fergus@bonhard.uklinux.net>
To: <cygwin@cygwin.com>
Cc: <fergus@bonhard.uklinux.net>
Subject: Easy? sed syntax
Date: Thu, 26 Oct 2006 07:23:02 +0100
Message-ID: <000001c6f8c7$3452f4b0$240210ac@tcgp.dundee.ac.uk>
MIME-Version: 1.0
Content-Type: text/plain; 	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
X-UoD-Scan-Signature: 8ed474cad03db73ca2730ed11f3709e4
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Please can anybody help with a simply-stated sed problem? I realise this is
not Cygwin-specific, but it is Cygwin-relevant because it is required in
order to write a script to mount a portable Cygwin system on any host
machine, so I hope it's all right to ask for help here.

The problem reduces to:

In any string (eg "xaaabababbbxaabbbabx") remove all instances of "ab" and
keep on doing this as long as you can.

Do it once:

    echo xaaabababbbxaabbbabx | sed 's/ab//g'
    xaabbxabbx

The essential issue is that that removal of all instances of "ab" has
created new instances of "ab" in the reduced string, so it needs to be done
again:

    echo xaaabababbbxaabbbabx | sed 's/ab//g' | sed 's/ab//g'
    xabxbx

and it needs to be done a 3rd time to reach the irreducible string

    echo xaaabababbbxaabbbabx | sed 's/ab//g' | sed 's/ab//g' | sed
's/ab//g'
    xxbx

Different initial strings might need more passes through sed, and it's not
possible to forecast how many passes will be needed (well, it is, but only
by a complex counting algorithm). Is there a way with a single sed command

    echo xaaabababbbxaabbbabx REPEAT{| sed 's/ab//g'}

that I can "repeat the pipe as many times as possible" and then stop?

Don't know whether this is obvious/ simple/ difficult/ possible/ or any of
these: thank you. 

Fergus


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

