Last active
November 20, 2020 10:43
-
-
Save maxpeterson/68dae0e36a493bab81ebae84186f8428 to your computer and use it in GitHub Desktop.
Convert file contents from snake_case to camelCase
This file contains 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/sh | |
if [[ "$@" == "" ]]; then | |
echo "$0: No files specified" | |
echo "$0 <file> [<file2>]" | |
exit 1 | |
fi | |
for file in $@; do | |
tmpfile="$(mktemp /tmp/$(basename $file).XXXXXXXXX)" | |
awk '{ | |
head = "" | |
tail = $0 | |
while ( match(tail,/[[:lower:][:digit:]]_[[:lower:][:digit:]]/) ) { | |
head = head substr(tail,1,RSTART-1) substr(tail,RSTART, 1) toupper(substr(tail,RSTART+2, 1)) | |
tail = substr(tail,RSTART+3) | |
} | |
print head tail | |
}' "$file" > "$tmpfile" | |
mv "$tmpfile" "$file" | |
done |
Author
maxpeterson
commented
Nov 17, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment