How Do I Extract Records/Fields from Text File & Use to Create RTF Files?

OK, I think this should do the trick.

Using the source text file, it will

  1. Extract each text block as a "record"
  2. Extract all of the fields from that record
  3. Use those fields to create a RTF file.
  4. Repeat for each text block found.

It should run as is, but you probably will want to set the default paths for the Source and Output folders first.

image

Please feel free to post any questions, issues, and/or suggestions concerning this macro.


Example Output

image

image


MACRO:   Extract Records/Fields from Text File & Output to RTF Files [Example]


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/8/4/844164aa7ed305f0a018a1709522338aa8d28c8c.kmmacros">Extract Records-Fields from Text File & Output to RTF Files [Example].kmmacros</a> (45 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---

### ReleaseNotes

Author.@JMichaelTX

**PURPOSE:**

* **Extract Blocks of Text from File as Records**
* and Output as RTF Files

**REQUIRES:**

1. **KM 8.2+**
  * But it can be written in KM 7.3.1+
  * It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
.
2. **macOS 10.11.6 (El Capitan)**
  * KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees.  :wink: 

**NOTICE: This macro/script is just an _Example_**

* It has had very limited testing.
* You need to test further before using in a production environment.
* It does not have extensive error checking/handling.
* It may not be complete.  It is provided as an example to show you one approach to solving a problem.

**How To Use**

1. Create Source Text File
   * Each Record (text block) must:
     * Start with "Place:"
     * End with "###:"
2. Make sure Source and Output Folders are set in Macro
3. Trigger this macro.
   * It will then ask for Source file
   * Extract a Record and Fields
   * Output a RTF File
   * for each Record found in file
   * Open Output folder in Finder

**MACRO SETUP**

* **Carefully review the Release Notes and the Macro Actions**
  * Make sure you understand what the Macro will do.  
  * You are responsible for running the Macro, not me.  ??
.
1. Assign a Trigger to this maro..
2. Move this macro to a Macro Group that is only Active when you need this Macro.
3. ENABLE this Macro.
.
* **REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:**
(all shown in the magenta color)
  * Prompt for Source and Output Folders

TAGS: @RegEx @Extract @Records @Fields @RTF @Files @Example

USER SETTINGS:

* Any Action in _magenta color_ is designed to be changed by end-user

ACTION COLOR CODES

* To facilitate the reading, customizing, and maintenance of this macro,
      key Actions are colored as follows:
* GREEN   -- Key Comments designed to highlight main sections of macro
* MAGENTA -- Actions designed to be customized by user
* YELLOW  -- Primary Actions (usually the main purpose of the macro)
* ORANGE  -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions


**USE AT YOUR OWN RISK**

* While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
  * **Ask first**
  * Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

---

![image|451x2000](upload://mvQwKrc7PULQlzsKK4ctsmryFpy.jpg)
1 Like