#!/bin/bash
thecommand="${1}"
if [[ -z "${thecommand}" ]]; then
  echo "Must pass in a thecommand"
  echo "'ls machine@*|sort'"
  exit 1
fi

templist=$(echo "${thecommand}"|sed 's/,/ /g')

filelist=$(
  for i in ${templist}; do
    if ( echo "${i}"|grep -q '@' ); then
      ls -1 $(echo ${i}|sed 's/@.*//')@*.txt
    else
      echo ${i}
    fi
  done|awk '{myvar=myvar" "$0}END{print myvar}'|sed -E 's/  / /g'|sed 's/ /\n/g'|sort -u|awk '{myvar=myvar" "$0}END{print myvar}'
)

for i in ${filelist}; do
  line=$(echo "${i}"|sed 's/.txt//')
  echo "addParent(\"triumph:$(basename $(pwd))/${line}\")"
done
grep criteria ${filelist}|sed -E 's/^.*:(criteria.*)/\1/'
