Nim is _so_ flexible!

I recently was doing some text processing and decided to try awk, which really 
does amazingly well in its domain, ie taking some tabular data and crunching it 
and putting out some kind of text format.

I had tried to do it in Nim first but there was too much boilerplate- that is, 
until I realized you can bolt strformat onto stdtmpl without bothering to use a 
proc, and have something similarly concise to awk scripts. This script expects 
TSV input with two columns and left-aligns the first, right aligns the second, 
creating a markdown table.
    
    
    #? stdtmpl(emit="stdout.write &")
    # import strformat, streams, parsecsv
    # var x: CsvParser
    # open(x, newFileStream(stdin), "-", '\t')
    
    My Report
    =========
    
    {"":-<20} {"":-<20}
    # while x.readRow():
    {x.row[0]:<20} {x.row[1]:>20}
    # end
    {"":-<20} {"":-<20}
    
    
    Run
    
    
    foo\t1
    bar\t2
    fuz\t3
    buz}t4
    
    
    Run

Reply via email to