Skip to content

Instantly share code, notes, and snippets.

@nafiesl
Last active May 2, 2023 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nafiesl/8cb5d809748a080e06132a1c15725de9 to your computer and use it in GitHub Desktop.
Save nafiesl/8cb5d809748a080e06132a1c15725de9 to your computer and use it in GitHub Desktop.
Basic File Generator using Bash Script
[
{"name": "website_1", "age": 1},
{"name": "website_2", "age": 2},
{"name": "website_3", "age": 3}
]
#!/bin/bash
# Load data from the JSON file
data=$(cat data.json)
# Loop through the data and generate a file for each item
for item in $(echo "${data}" | jq -r '.[] | @base64'); do
# Decode the base64-encoded item and extract the name and age values
_jq() {
echo ${item} | base64 --decode | jq -r ${1}
}
name=$(_jq '.name')
age=$(_jq '.age')
# Replace the placeholders in the template with the actual values
cat template.txt | sed "s/{name}/$name/g; s/{age}/$age/g" > "${name}.txt"
done
data1 = {name}
data2 = {age}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment