This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Easy? sed syntax

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'

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

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

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

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. 


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]