Created
October 24, 2021 14:57
-
-
Save altbdoor/a183624d0d0e3314988ada2a9a4eef62 to your computer and use it in GitHub Desktop.
Manually getting the date in filename with awk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| CURRENT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" && pwd )" | |
| cd "$CURRENT_DIR" | |
| workpath="$1" | |
| cd "${workpath}" | |
| for image in *.jpeg; do | |
| date_format=$(echo "${image}" | awk '{gsub(/-/, ":", $3); print $3}') | |
| time_format=$(echo "${image}" | awk '{print $5}') | |
| twelve_h_format=$(echo "${image}" | awk '{sub(/M.+/, "M", $6); print $6}') | |
| hour=$(echo "${time_format}" | awk -F "." '{print $1}') | |
| if [[ "${twelve_h_format}" == "PM" ]]; then | |
| hour=$((hour + 12)) | |
| fi | |
| hour=$(printf "%02d" "${hour}") | |
| minute_and_second=$(echo "${time_format}" | awk -F "." '{print $2":"$3}') | |
| time_format="${hour}:${minute_and_second}" | |
| full_datetime="${date_format} ${time_format}" | |
| "$CURRENT_DIR/exiftool.exe" -overwrite_original "-AllDates=${full_datetime}" "${image}" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment