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 X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Thu, 5 Sep 2002 21:38:32 -0400 (EDT) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Max Bowsher cc: cygwin AT cygwin DOT com Subject: Re: Calling all sed wizards! Need a little help with possible fix: Subtle permissions bug in interaction between Makefiles & libtool (Cygwin-specific) In-Reply-To: <00c401c2552a$4b497d50$0100a8c0@wdg.uk.ibm.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Thu, 5 Sep 2002, Max Bowsher wrote: > Igor Pechtchanski wrote: > > On Thu, 5 Sep 2002, Max Bowsher wrote: > > > >> I had an idea: > >> sedpat6='s,\(-m [0-7]*\)6,\17,g' > >> sedpat4='s,\(-m [0-7]*\)4,\15,g' > >> sed -e "$sedpat4" -e "$sedpat4" -e "$sedpat4" -e "$sedpat6" -e > >> "$sedpat6" -e "$sedpat6" > >> > >> but can anyone show me a way without repeating each pattern 3 times? > > > > Hmm, "perl -pe 's/(?<=-m )([0-7]+)/($a=$1)=~tr,046,157,;$a/ge'"? O:) > > Yep, but given that this is for use in libtool, it can't rely on perl. > Max. Okay, then... There is a pure sed solution that doesn't use repetition. It's peculiar, and involves a loop. In this particular case, you are probably better off just repeating the patterns 3 times. But I'm posting it just to show that it can be done. Call me vain. :-D Okay, here goes: sed 's/$/0^A1^A2^B3^C4^E5^E6^G7^G/;:a;s/\(-m [0-7^A-^G]*\)\([0-7]\)\(.*\2\)\(.\)/\1\4\3\4/;ta;s/.\{16\}$//;y/^A^B^C^E^G/12357/' where ^A through ^G above are actually control characters (use ^V to enter at the prompt). They don't have to be those exact ones, but they should be characters that can't appear in the rest of the string (because of the 'y' command). For those who want to decipher the code yourself, stop reading now. Spoiler below: The first substitution appends a fixed-length map from numbers to associated control characters. The second is in a loop, and basically substitutes any number found after a "-m [0-7^A-^G]*" with the associated character from the map, while there are characters available. The third substitution removes the map, and the 'y' command translates the control characters back into digits. I got the idea from the word capitalization script here: http://users.cybercity.dk/~bse26236/batutil/help/sed/CAPITALI.HTM Enjoy, Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! It took the computational power of three Commodore 64s to fly to the moon. It takes a 486 to run Windows 95. Something is wrong here. -- SC sig file -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/