Skip to content

Instantly share code, notes, and snippets.

@maxpeterson
Last active November 20, 2020 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxpeterson/68dae0e36a493bab81ebae84186f8428 to your computer and use it in GitHub Desktop.
Save maxpeterson/68dae0e36a493bab81ebae84186f8428 to your computer and use it in GitHub Desktop.
Convert file contents from snake_case to camelCase
#!/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
@maxpeterson
Copy link
Author

maxpeterson commented Nov 17, 2020

ack '[[:lower:][:digit:]]_[[:lower:][:digit:]]' src_dir -l | xargs ./snakeToCamel.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment