I have a flat file of records, each 33 lines long. I need to format this file to specs in a template. The template is in DOS format while the source file is in NIX format. The template has specific indenting and spacing which must be adhered to. I've thought of a few options:
- BASH with classic nix tools: sed, awk, grep etc...
- BASH with template toolkit
- Perl eith template toolkit
- Perl
These are in order of my familiarity. Here's a sample source record ( NIX format ): I've reduced the number of newlines to save space ( normally 33 lines ):
JACKSON HOLE SANITARIUM AND REPTILE ZOO
45 GREASY HOLLER LN
JACKSON HOLE, AK 99999
Change Service Requested
BUBBA HOTEP
3 DELIVERANCE RD
MINNEAPOLIS, MN 99998
BUBBA HOTEP 09090909090909
You have a hold available for pickup as of 2012-01-04:
Title: Banjo for Fun and Profit
Author: Williams, Billy Dee
Price: $10
Here's the template ( DOS format -- lines reduced - 66 lines normally):
<%BRANCH-NAME%>
<%BRANCH-ADDR%>
<%BRANCH-CTY%>
<%CUST-NAME%> <%BARCODE%>
You have a hold available for pickup as of <%DATE%>:
Title: <%TITLE%>
Author: <%AUTHOR%>
Price: <%PRICE%>
<%CUST-NAME%>
<%CUST-ADDR%>
<%CUST-CTY%>
end of file
It actually does say "end of file" at the end of each record.
Thoughts? I tend to over-complicate things.
UPDATE2
Figured it out.
My answer is below. Feel free to suggest improvements.
This is what I am using for this project. Feel free to suggest improvements, or, submit better solutions.