Part of Nobumi Iyanaga's website. n-iyanag@ppp.bekkoame.ne.jp. 10/25/03.

logo picture

Unix grep for Nisus Writer Express

This is a little grep macro that can be used from within Nisus Writer Express. You can use Nisus Writer Express as the user interface for Unix grep, and search in UTF-8 text files for words containing Unicode characters.

Requirements

How to Install

  1. Put UnixGrep.scpt in /Users/[your_account]/Library/Application Support/Nisus Writer/Macros/UnixGrep.scpt

  2. Download Jon's Commands X from http://www.seanet.com/~jonpugh/, and put it in /Users/[your_account]/Library/ScriptingAdditions/ (if the folder "ScriptingAdditions" does not exist in your Library, create it; note that there is no space between "Scripting" and "Additions").

How to Use

I assume that you have launched Nisus Writer Express, and you have a Nisus Writer Express window open on your screen.
I assume also that you have folders full of TEXT files in UTF-8, with ".txt" extension.

  1. Type any word you want to look for in your Nisus Writer Express window, and select it. You can use Unicode characters in this word.
  2. Run the script "UnixGrep.scpt", choosing "UnixGrep" from Macros menu in Nisus Writer Express.
  3. A file dialog opens, asking you to locate the folder in which you want to do your search. Navigate to that folder, and press the button "Choose".
  4. After a while, a new window will open in Nisus Writer Express, with the title "grepRes.txt". It displays the result of your grep search.

Warning:
The file "grepRes.txt" is created on your Desktop (its encoding is UTF-8). You can open it with any Unicode savvy editor, e.g. TextEdit. You can use it, edit it, etc., but if you edit it, please save the result in another file, using "Save As...". This file will be overwritten by the next use of UnixGrep.scpt; if it is open and edited at that time, there will be an error.

How to Configure grep options

The default grep options is -Hbn, that means:

There are other options that you can set. To set options,
Choose "UnixGrep" in Macros menu while holding down the Shift key. A list selecting dialog, with the following options, will appear:

Case insensitive
Match words
Extended regex
Recursive search
---
Print byte offsets
Print line numbers
Print file names
Print multiple lines

You can select multiple options clicking on the items while holding down the Command and the Option keys.
If you select "Print multiple lines", another dialog will appear, asking you to put the number of lines to output, with the default number "1". This is the number of line(s) that will be in the output before and after the matched line. So if it is "1", there will be 3 lines for each matched item. The maximum is "5" in this script.
The item "---" is a simple separator between the search options and the output options. Don't choose this item (if you select it, the options will be set to the "factory default", i.e. "Print file names", "Print byte offset" and "Print line numbers").

When you have selected once the options, they will be the default for next times. If you want to change again the options, choose again "UnixGrep" with the Shift key down.

To view the current options, choose "UnixGrep" while holding down the Option key. The script will display the current options and quit.

If you choose "UnixGrep" while holding down both the Shift key and Option key, you will be able to change the grep options, diaplay these options, and quit the script without performing the search.


Download

Please download "UnixGrep.scpt" from this link (8 KB).

I would appreciate any feedback, bug report, suggestions. Thank you in advance!


Go to Research tools Home Page
Go to NI Home Page


Mail to Nobumi Iyanaga


frontierlogo picture

This page was last built with Frontier on a Macintosh on Sat, Oct 25, 2003 at 6:04:11 PM. Thanks for checking it out! Nobumi Iyanaga