make_from_template.sh 1.3 KB

123456789101112131415161718192021222324252627
  1. #!/bin/sh
  2. if [ -z "$1" ] || [ -z "$2" ]; then
  3. echo "Usage example: make_from_template.sh path/to/example_recipe_{{1a}}.json.template list.tsv"
  4. echo "or: make_from_template.sh path/to/example_from_{{1}}_to_{{2}}.json.template list1.txt list2.txt"
  5. exit 1
  6. fi
  7. if [ -z "$3" ]; then
  8. while read -r replace1a replace1b replace1c replace1d; do
  9. replace1="$replace1a"
  10. new_filename="$(printf '%s' "$1" | sed "s/{{1}}/$replace1/g; s/{{1a}}/$replace1a/g; s/{{1b}}/$replace1b/g; s/{{1c}}/$replace1c/g; s/{{1d}}/$replace1d/g; s/.template\$//")"
  11. echo "$new_filename"
  12. < "$1" sed "s/{{1}}/$replace1/g; s/{{1a}}/$replace1a/g; s/{{1b}}/$replace1b/g; s/{{1c}}/$replace1c/g; s/{{1d}}/$replace1d/g" > "$new_filename"
  13. done < "$2"
  14. else
  15. while read -r replace1a replace1b; do
  16. replace1="$replace1a"
  17. while read -r replace2a replace2b; do
  18. replace2="$replace2a"
  19. new_filename="$(printf '%s' "$1" | sed "s/{{1}}/$replace1/g; s/{{1a}}/$replace1a/g; s/{{1b}}/$replace1b/g; s/{{2}}/$replace2/g; s/{{2a}}/$replace2a/g; s/{{2b}}/$replace2b/g; s/.template\$//")"
  20. echo "$new_filename"
  21. < "$1" sed "s/{{1}}/$replace1/g; s/{{1a}}/$replace1a/g; s/{{1b}}/$replace1b/g; s/{{2}}/$replace2/g; s/{{2a}}/$replace2a/g; s/{{2b}}/$replace2b/g; s/.template\$//" > "$new_filename"
  22. done < "$3"
  23. done < "$2"
  24. fi