X-Spam-Check-By: sourceware.org From: "fergus" To: Cc: 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 AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT 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/