From the monthly archives:

November 2006

Replace in technicolour

by Miraz Jordan on November 29, 2006

Replace in technicolour
Mac Tip #271/29-Nov-2006

The free text editor Tex-Edit Plus can do one extraordinarily useful thing that many or most other text editors cannot: you can find and replace styled text.

That means, among other things, that you could find the word “the” and replace it with “my” using a colour such as red or green. Or, you can identify just where you’ve used a particular word by replacing it with itself, but in a different colour from the surrounding text.

Once the replace operation is complete you need only glance at the text to see which words have been changed. The coloured text jumps out and you may immediately see that all kinds of unintended replacements have been made, or, with luck, that the operation made exactly the changes you expected.

Open Tex-Edit Plus and enter some text — copy and paste this Tip perhaps.

Replace with a colour. Now call up the Find & Replace dialog from the Edit > Find menu. Enter the text to Find and the text to Replace with in the text boxes. Then click the small arrow at the right-hand end of the Replace text box and choose Color > Red. You should see that the text in the Replace with text box turns red. Now click the Replace All button.

[Click on the thumbnails for larger images.]

Tex-Edit Plus makes the replacements then puts up an alert to tell you how many replacements it made. Click OK to dismiss the alert. The replacements are displayed in red, or whatever colour you chose.

Replacements are easy to spot. If you see problems choose Undo from the Edit menu.

Note: Tex-Edit Plus has multiple levels of Undo. That means you can undo more than just the last one operation. It can even Undo back past a Save, provided you haven’t closed the document in the meantime.

Next week: E=mc cubed.

Popularity: 7% [?]

{ No comments yet }

Count with Find and Replace

by Miraz Jordan on November 23, 2006

Count with Find and Replace
Mac Tip #270/22-Nov-2006

A reader reminded me that Find and Replace is a quick way to do some counting in your text. For example, perhaps you need to count how many times you’ve used a particular word — did you mention Product A as often as you mentioned Product B? Or perhaps you’d like to make sure you closed all the brackets you used.

Call up the Find and Replace dialog box for your software and enter your Search term, perhaps Apple, then put the same term in the Replace section. You’re replacing a word with the same word.

Now click Replace All. Most software gives you some kind of acknowledgement of how many replaces it made — perhaps as a simple count in the still open Find and Replace dialog box, or maybe in a separate alert, as you can see in the screenshots. [Click on the thumbnails to see larger versions.]

TextEdit shows how many replacements it made. . Tex-Edit Plus reports replacements in an alert.

Be careful though: watch out for words embedded in other words. If you need to count how often you’ve used the word ‘the’, then you should include a space after it, otherwise the program may also count anything where those letters appear consecutively such as in ‘there’, ‘either’ or ‘clothes’. Even the trailing space may not be sufficient, for some Blithe Spirits.

Next week: Replace in technicolour.

Popularity: 13% [?]

{ 1 comment }

Pattern Replace (3)

by Miraz Jordan on November 15, 2006

Pattern Replace (3)
Mac Tip #269/15-Nov-2006

Recent Tips have shown how to switch a pair of names using grep in Tex-Edit Plus and Microsoft Word. Please read those Tips again to refresh your memory of what’s going on. We used a regular expression to switch around names

This time we do a similar thing with TextWrangler, a free text editor from BareBones.

The reason for doing the same task in three different applications is to show that the fundamentals are the same, or similar, for each program, although details may vary. Moreover, different programs may offer slightly different grep features.

For example, TextWrangler has a ‘word boundary’ feature that we use this week to find ‘words’ rather than just ‘groups of letters’.

Download TextWrangler and paste in a list of reversed names:

  • Janeway, Kathryn
  • Summers, Buffy
  • Carter, Samantha
  • Torres, B’Elanna

Search

Press Command F to call up the Find and Replace dialog box and be sure to check the Use Grep checkbox.

The word boundary

TextWrangler allows us to look for a word boundary, and that’s just what we want: one word followed by a comma and space and then another word. The word boundary (\b) lets us construct a search to find any number of characters (.+) within the bounds of a word:

Search for: (\b.+\b), (\b.+\b)

Replace with: \2 \1

Click the Replace All button to switch the reversed names around to the first-last order we require. TextWrangler flashes up an alert to advise you that it has made the replacements.

This Regular Expression handles the apostrophe in a name without problems.

Next week: More Find and Replace tips

Popularity: 11% [?]

{ No comments yet }

Scenic New Zealand.