Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save IAmSurajBobade/a73925e9791908eb0c1d3250188b6440 to your computer and use it in GitHub Desktop.

Select an option

Save IAmSurajBobade/a73925e9791908eb0c1d3250188b6440 to your computer and use it in GitHub Desktop.
Shell script
#!/bin/bash
# Check if exactly 2 arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <input_directory> <output_directory>"
exit 1
fi
INPUT_DIR="$1"
OUTPUT_DIR="$2"
# Check if input directory exists
if [ ! -d "$INPUT_DIR" ]; then
echo "Error: Input directory '$INPUT_DIR' does not exist"
exit 1
fi
# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
if [ $? -ne 0 ]; then
echo "Error: Could not create output directory '$OUTPUT_DIR'"
exit 1
fi
# Find all .aql files and process them
found_files=false
while IFS= read -r -d '' file; do
found_files=true
# Get filename without path and extension
filename=$(basename "$file" .aql)
output_file="$OUTPUT_DIR/${filename}_output.txt"
echo "Processing $file -> $output_file"
# Run aql command and redirect output (stdout and stderr)
aql "$file" > "$output_file" 2>&1
if [ $? -eq 0 ]; then
echo "Successfully processed $file"
else
echo "Error processing $file (check $output_file for details)"
fi
done < <(find "$INPUT_DIR" -type f -name "*.aql" -print0)
if [ "$found_files" = false ]; then
echo "No .aql files found in $INPUT_DIR"
fi
echo "Processing complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment