Sample Header Ad - 728x90

Simple template engine for bash, that can use csv data?

2 votes
1 answer
333 views
I'd often like to quickly take some data, and apply it to a template in bash. e.g. imagine doing the following $ seq 1 2 | eztemplate 'this is a {1} test' this is a 1 test this is a 2 test $ eztemplate 'this is a {1} test' hi 'there now' this is a hi test this is a there now test $ eztemplate /tmp/template /tmp/alphabet | head this is a a test of this system a this is a b test of this system b ... I've wrote a very simple bash script that does this, but was considering allowing multiple parameters, like CSV style data, per line of data. ### Does something better than my little script already exist, given the following? - I want it to require only basic unix posix tools, and commonly installed things like perl or awk, but requires no modules be installed additionally by perl, for example - It can accept multiple columns of data, per line of data in the data file. - Basically is one bash script that doesn't require installing anything else :D - A side intent is to allow others that aren't great at bash scripting to have a simple tool to process templates for repeating data The data and template will vary greatly, but the first example I wanted to do it with was apply 4 ids to a JSON payload *template* { "tenantId": "{1}", "key": "some.key", "value": "some.value" } *data* my/super/01cbf4e9779649038f0bd753747c8b26 my/test/01cbf4e9779649038f0bd753747c8b26 ez/test/01cbf4e9779649038f0bd753747c8b26 rad/data/df3a47fed39d453f836f9b2196332029 ## eztemplate #!/usr/bin/env bash DIR="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"; PATH="$DIR:$PATH" function show_help() { ME=$(basename "$0") IT=$(cat <
Asked by Brad Parks (1779 rep)
Mar 3, 2023, 04:18 PM
Last activity: Mar 3, 2023, 07:53 PM