Skip to content

Instantly share code, notes, and snippets.

@taiju
Last active July 26, 2018 08:25
Show Gist options
  • Save taiju/df174af9a72477921850933faee9e82e to your computer and use it in GitHub Desktop.
Save taiju/df174af9a72477921850933faee9e82e to your computer and use it in GitHub Desktop.
TSVを元にテンプレートをビルドする時に使えそうなイディオム

コマンド

$ seq 2 4 | xargs -n1 -i bash -c 'read $(head -n1 data.tsv) < <(sed -n {}p data.tsv) && export $(head -n1 data.tsv) && envsubst < tmpl.json > row-{}'

データ等

$ ls -1
data.tsv
tmpl.json
$ cat tmpl.json
{
  "foo": "${FOO}",
  "bar": "${BAR}",
  "baz": "${BAZ}"
}
$ cat data.tsv
FOO	BAR	BAZ
aaa	bbb	ccc
ddd	eee	fff
ggg	hhh	iii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment