cv-latex/update-age.sh
Louis b132659a7a
All checks were successful
ci/woodpecker/push/age-check Pipeline was successful
CI: adding age check ci
2025-04-29 16:11:44 +02:00

33 lines
No EOL
765 B
Bash
Executable file

#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <file>";
echo "Example: $0 /path/to/file.txt";
echo "Please provide a file as an argument.";
exit 1;
fi
if [ ! -f $1 ]; then
echo "File $1 not found";
echo "Usage: $0 <file>";
echo "Example: $0 /path/to/file.txt";
exit 1;
fi
AGE_W=$(grep -oP "([0-9]{2}) ans" $1 | grep -oP "([0-9]{2})")
if [ -z "$AGE_W" ]; then
echo "Age not found in $1";
exit 1;
fi
echo "Age found: $AGE_W"
AGE_R=$(($(date +%Y)-2000))
echo "Current age: $AGE_R"
if [ "$AGE_W" -eq "$AGE_R" ]; then
echo "Age in $1 ($AGE_W) matches current year ($AGE_R)";
exit 0;
else
echo "Age in $1 ($AGE_W) does not match current year ($AGE_R)";
echo "Updating age in $1";
sed -i -e "s/$AGE_W ans/$AGE_R ans/" $1;
echo "Age updated to $AGE_R in $1";
cat $1
fi