Thursday, March 03, 2011

Frodo, the LOTR - Browse Files at SourceForge.net

Frodo, the LOTR - Browse Files at SourceForge.net: "Frodo is a Line-Oriented Text Rewriter, a tool for scripting bulk
rewrites of line-oriented text data. It can be used for reformatting
data, or for other editing tasks more challenging than
global-search-and-replace.

The easiest way to explain is just to give some examples. Suppose
you have a data file that looks like this:

last='Ambrose' first='Alice' bdate='1885-04-22'
last='Baldwin' first='Bernard' bdate='1887-09-13'
last='Corbin' first='Charles' bdate='1879-11-03'
last='Dalton' first='Dennis' bdate='1881-01-07'

That's nice and all, but it would be more convenient if it were in
CSV format, with maybe a header that gave names to the column. This
is a perfect job for Frodo. Try this script on it.

insert 'LAST,FIRST,BDATE'
while (
replace /last='(.*)' first='(.*)' bdate='(.*)'/ |{1},{2},{3}|
next
)

You'll get something that looks like this.

LAST,FIRST,BDATE
Ambrose,Alice,1885-04-22
Baldwin,Bernard,1887-09-13
Corbin,Charles,1879-11-03
Dalton,Dennis,1881-01-07"