[mdlug] Another sed/regex question

Carl T. Miller carl at carltm.com
Sat Sep 27 06:38:14 EDT 2014


Jeff Hanson wrote:
> The program is WeiDu, a mod installer for Infinity engine games (Baldur's
> Gate, etc.) I'm generating a highlighted list based on component IDs that
> will be installed.
>
> weidu output (long lines will wrap in email):
> [./chitin.key] 357 BIFFs, 54184 resources
> [./dialog.tlk] 94183 string entries
> [widescreen/tra/english/setup.tra] has 31 translation strings
> ~WIDESCREEN/WIDESCREEN.TP2~ #0 #0 // Widescreen Mod -> for the original
> Infinity Engine (CHOOSE THIS!): Widescreen Mod v3.02
> ~WIDESCREEN/WIDESCREEN.TP2~ #0 #1 // Widescreen Mod -> for GemRB:
> Widescreen Mod v3.02
>
> First #0 is language ID and doesn't change.  The second #digit is the
> component ID, followed by two undesirable forward slashes and the
> component
> ID description.  Given an installed component ID of 0, output from current
> sed mess is as follows (\x1b is sed replacement hex for ESC):
>
> \x1b[1;32m0 Widescreen Mod -> for the original Infinity Engine (CHOOSE
> THIS!): Widescreen Mod v3.02\x1b[0m
> \x1b[0;31m1 Widescreen Mod -> for GemRB: Widescreen Mod v3.02\x1b[0m
>
> The first matches and is green, the second doesn't and is red.  What I use
> now works but is really ugly.  I'm just looking for a way to choose
> between
> two different replacements based on a successful match.  The search
> pattern
> uses grouping and the replacements use backreferences to select the ID and
> description from the input.

Okay, now I understand it.  And now I understand that phrase
"beauty is in the eye of the beholder."  To me your original
sed line with the two expressions was an elegant solution,
which I appreciate all the more after finding that sed does
not have an "else" syntax.

c




More information about the mdlug mailing list