Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.