#!/usr/bin/env bash

# Parse a transaction sales file.
# Omit unused fields.
# Add numeric ids.
USAGE='Usage: ./prepare_txn_file.sh /path/to/file.tsv start_id'

# TODO - source the staging dir from the .env file
# TODO - get the start id from redis-cli

# Argument 1: valid filepath
# Argument 2: numeric id to start at
if ! [ -f "$1" -o "$2" -ge 0 ]; then
    echo "$USAGE"
    exit 1
fi

# Stream the file, removing column 7.
# Remove double quotes.
# Add a unique numeric id to each line.
cat "$1" | cut -f1-5,8- | sed 's/"//g' | awk '{printf("%s\t%s\n", NR+${2}, $0)}' > txns.tsv
