Last active
May 2, 2023 13:38
-
-
Save nafiesl/8cb5d809748a080e06132a1c15725de9 to your computer and use it in GitHub Desktop.
Basic File Generator using Bash Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{"name": "website_1", "age": 1}, | |
{"name": "website_2", "age": 2}, | |
{"name": "website_3", "age": 3} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data1 = {name} | |
data2 = {age} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment