fix(cmd/sendsms): randomize-csv now keeps header and adds back extension

This commit is contained in:
AJ ONeal 2026-02-22 15:09:02 -07:00
parent 7b40097396
commit 4e5277d133
No known key found for this signature in database
2 changed files with 37 additions and 39 deletions

37
cmd/sendsms/randomize-csv Executable file
View File

@ -0,0 +1,37 @@
#!/bin/sh
set -e
set -u
g_csv="${1:-}"
g_dir=$(dirname "${g_csv}")
g_rnd="${g_csv}"
g_rnd=$(basename "${g_rnd}" ".csv")
g_rnd="${g_dir}/${g_rnd}.rnd.csv"
fn_help() {
echo "USAGE"
echo " # sort -R ./list.csv > ./list.rnd.csv"
echo " ./randomize-csv ./list.csv"
}
main() {
if test -z "${g_csv}" || ! test -s "${g_csv}"; then
>&2 fn_help
return 1
fi
if test -s "${g_rnd}"; then
{
echo "${g_rnd} already exists"
} >&2
return 1
fi
head -n 1 "${g_csv}" > "${g_rnd}"
tail -n +2 "${g_csv}" | sort -R >> "${g_rnd}"
{
echo "wrote ${g_rnd}"
} >&2
}
main

View File

@ -1,39 +0,0 @@
#!/bin/sh
set -e
set -u
g_csv="${1:-}"
fn_help() {
echo "USAGE"
echo " # sort -R ./list.csv > ./list.csv.bak"
echo " ./randomize.sh ./list.csv"
}
fn_tip() {
echo "IMPORTANT"
echo " Now go move the header back to the first row"
}
main() {
if test -z "${g_csv}" || ! test -s "${g_csv}"; then
>&2 fn_help
return 1
fi
if test -s "${g_csv}.randomized"; then
{
echo "${g_csv}.randomized already exists"
fn_tip
} >&2
return 1
fi
sort -R "${g_csv}" > "${g_csv}.randomized"
{
echo "wrote ${g_csv}.randomized"
fn_tip
} >&2
}
main