On 7/26/17 at 1:45 PM,
calo...@gmail.com (Calion) wrote:
>Okay, for a newbie to Grep, I feel like I've gotten pretty far.
>
>So far, I've got
>^([^ ]+\t[[:upper:]]+\d+)
>
>Replaced by
>
>\1\t
>
>Great! That works (well, sort of. For some reason it matched
>more than just uppercase letters, but as it turned out, that's
>what I wanted anyway, so whatever).
Enable 'Case senstive' for matching.
>But now I want to insert an extra tab after the initial string (prior
>to the first tab) for every line that does *not* match the second part
>of the expression (after the tab). But I have absolutely no idea how
>to do this.
>
>An example to make things clear:
>
>The expression above matches
>
>9308 DDREF1 D&D Character Record Sheets (ca. 1991)
>
>but not
>
>9363 Character and Monster Assortment Pack
>
>Fantastic. But now I need an additional tab after the numbers
>for only the bottom (unmatched) line.
Make the [[:upper:]]+\d+ part of your expression optional:
^([^ ]+\t(?:[[:upper:]]+\d+)?)
So now it matches
9308\tDDREF1
in your first example line and
9363\t
in the second. The replacement pattern \1\t will now give you
9308\tDDREF1\t
and
9363\t\t
--
Christopher Bort
<
top...@thehundredacre.net>