Skip to main content

sadfzxcv

#!/bin/bash
#
# This script loads all tables in /stuff/kdb, runs a hardcoded multi-line Q-syntax query,
# and writes the results into /home/stuff/output with a timestamped filename.

# Move to the kdb directory
cd /stuff/kdb || {
  echo "Error: Failed to cd into /stuff/kdb. Check that it exists."
  exit 1
}

# Hardcoded multi-line Q/SQL-like query
# (Adjust the actual code to your use case)
read -r -d '' MULTI_LINE_SQL <<'EQUERY'
select from trades
 where sym in `AAPL`MSFT,
       time within 09:30 16:00
EQUERY

# Generate a timestamp
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")

# Hardcoded output directory (ensure this directory exists or create it beforehand)
OUTPUT_DIR="/home/stuff/output"

# Construct the output filename (e.g., output_20250310_143042.csv)
OUTPUT_CSV="${OUTPUT_DIR}/output_${TIMESTAMP}.csv"

# Run q with 1GB workspace
q -w 1000 <<EOF
  \l .
  results: $MULTI_LINE_SQL
  \`$OUTPUT_CSV 0: results
  \\
EOF

echo "Query results saved to: $OUTPUT_CSV"