Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeansymolanza/6cd4b2eb9aadc48a3b66aa073fd0ed70 to your computer and use it in GitHub Desktop.
Save jeansymolanza/6cd4b2eb9aadc48a3b66aa073fd0ed70 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Constants
readonly INPUT_DIR="/$(JUDYHOME)/batch/export/fiss/preprocess"
readonly OUTPUT_DIR="/loaded"
readonly EOD_MARKER="EOD"
readonly TRADE_MARKER="1.*"
readonly QUOTE_MARKER="9.*"
readonly LINE_LENGTH_THRESHOLD=2618
# Function to process a single file
process_file() {
local input_file="$1"
local temp_file="${input_file}_TMP_${RANDOM}"
local input_file_name=$(basename "$input_file")
# Check if the input file can be read
if [[ ! -r "$input_file" ]]; then
echo "Cannot open input file: $input_file"
return 1
fi
# Check if the temporary file can be written
if [[ ! -w "$(dirname "$temp_file")" ]]; then
echo "Failed to open output file: $temp_file"
return 1
fi
# Process the file line by line
while IFS= read -r line; do
process_line "$line" >> "$temp_file"
done < "$input_file"
# Move the updated temp file to the original input file
mv "$temp_file" "$input_file"
echo "Moving file to $OUTPUT_DIR"
mv "$input_file" "$OUTPUT_DIR"
}
# Function to process a single line
process_line() {
local line="$1"
local output_line=""
case "$line" in
"$EOD_MARKER")
output_line="EOD activity file, no amendments required"
;;
"$QUOTE_MARKER"* | "$TRADE_MARKER"*)
process_trade_or_quote "$line"
;;
*)
output_line="$line"
;;
esac
echo "$output_line"
}
# Function to process trade or quote lines
process_trade_or_quote() {
local line="$1"
local length=${#line}
if [[ $length -eq $LINE_LENGTH_THRESHOLD ]]; then
echo "${line:0:2610}"
else
echo "${line:0:2621}"
fi
}
# Main execution
main() {
for file in "$INPUT_DIR"/*.DAT; do
if [[ -f "$file" ]]; then
echo "Processing file: $file"
process_file "$file"
fi
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment