#!/bin/bash if [ $# -ne 1 ]; then echo "Usage: $0 "; 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 "; 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