SCR/SCR1.2/TP08/bin2dot-with-for.sh
2022-10-27 10:57:44 +02:00

30 lines
558 B
Bash
Executable File

#!/bin/bash
if [[ $# -lt 2 ]]
then
echo "Usage: $0 <SRC_FILE> <DEST_FILE>"
exit
fi
if [[ ! -f $1 ]]
then
echo "File $1 does not exist!"
exit
fi
if [[ -f $2 ]]
then
echo -n "File $2 already exists. Overwrite? Yes/No --> "
read answer
if [[ $answer != "Yes" ]]
then
exit
fi
cp /dev/null $2
fi
for addr in $(cat $1)
do
x=$(expr substr $addr 1 8)
y=$(expr substr $addr 9 8)
z=$(expr substr $addr 17 8)
t=$(expr substr $addr 25 8)
echo "$((2#$x)).$((2#$y)).$((2#$z)).$((2#$t))" >> $2
done
exit