Files
2026-11-24 17:20:05 +01:00

39 lines
802 B
Bash
Executable File

#!/bin/bash
if [[ $# -lt 3 ]]; then
echo "Usage: $0: <STRINGS_REPRESENTATION_FILE> <radix> <REPORTS_FILE>"
fi
if [[ $2 -lt 2 || $2 -gt 36 ]]; then
echo "radix should be between 2 and 36 !"
exit 1
fi
if [[ -f $3 ]]; then
read -p "reports file exists you want to overwrite it (Y/n) " choice
if [[ choice == "N" ]]; then
echo "user don't want to overwrite the report file exiting.."
exit 0
fi
cp /dev/null $3
fi
DIGITS=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
LEGAL_DIGITS=$(expr substr $DIGITS 1 $2)
while read line; do
report=""
l=$(expr length $line)
for ((i = 1; i <= l; i++)); do
digit=$(expr substr $line $i 1)
pos=$(expr index $LEGAL_DIGITS $digit)
if [[ pos -eq 0 ]]; then
report=$report$digit
fi
done
echo "$line : $report"
done <$1 >>$3