#!/bin/bash # relative or absolute path where the classes are path=../public/data/class/* # image filetype needs to be the same file_type=*.jpg # REGEX reg='(.*)class\/([0\-9A\-z_]*)\/([0\-9A\-z_]*)\.jpg' #reg='class\/([0\-9A\-z_]*)' for i in $path do if [ -d "$i" ]; then #echo "$i" json_file=$i/user.json printf '{\n"user":[\n'>$json_file for j in $i/* do if [[ $j == ${file_type} ]]; then if [[ $j =~ ${reg} ]]; then echo "${BASH_REMATCH[3]}" printf '"'>>$json_file printf ${BASH_REMATCH[3]}>>$json_file printf '",\n'>>$json_file else echo "TEST2" echo $j fi fi done cat $json_file | rev | cut -c 3- | rev fi done