Textism
 

Grep II  ::  MARCH 8

Continuing in tutorial mode, here’s one more bit of text wrangling with Grep.

The example text:

Kalman, Tibor: Hungary, 1994
Vignelli, Massimo: Italy, 1988
Weingart, Wolfgang: Neptune, 1972

Which needs to be in this format:

Hungary
1994: Tibor Kalman
Italy
1988: Massimo Vignelli
Neptune
1972: Wolfgang Weingart

Swapping around chunks of text, within a single paragraph, may seem impossible to automate. But a freaky good thing about Grep is its ability to assign values to the parts of a search, then reassemble the parts where you choose. In Word, remembering to turn Use Wildcards on, create a search string:

(*), (*): (*), (*)\n
Definitions:
() — parentheses define an expression: part of the search to be marked and remembered
* — an asterisk indicates one or more characters
\n — backslash n is Grep syntax for a line break

So we’re searching for: (something) comma space (something) colon space (something) comma space (something) line break

During the search, each instance of (something) is assigned a numeric value and remembered, so it can be called during the replace.

A replace string:

\3^l\4: \2 \1^l^l
Definitions:
\# — a backslash and a numeral indicate a found expression and its numeric value
^l — caret l is Word’s wonky syntax for a line break

So we’re replacing with: (third something) line break (fourth something) colon space (second something) space (first something) line break line break

Try it out. You will swoon.

 

BACK TO TEXTISM