Created
May 21, 2019 18:13
-
-
Save niflostancu/2947dba921f54b060d14119ddb5741f8 to your computer and use it in GitHub Desktop.
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 | |
NAMES_CSV="$(realpath "$2")" | |
set -e | |
cd "$1" | |
for dir in *; do | |
if [[ "$dir" =~ _([0-9]+)_ ]]; then | |
ID=${BASH_REMATCH[1]} | |
NEWNAME=$(cat "$NAMES_CSV" | grep -E "^[a-zA-Z]+$ID," | head -1 | awk -F',' ' | |
BEGIN { | |
FPAT = "([^, ]+)|(\"[^\"]+\")" | |
} { | |
if (substr($2, 1, 1) == "\"") { | |
len = length($2) | |
$2 = substr($2, 2, len - 2) # Get text within the two quotes | |
} | |
printf "%s-%s", $2, $3 | |
}') | |
NEWNAME=${NEWNAME%@*} | |
NEWNAME=${NEWNAME##* } | |
echo "$dir => $ID :: $NEWNAME" | |
mv "$dir" "$NEWNAME" | |
fi | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment