Skip to content

Instantly share code, notes, and snippets.

@jonmorehouse
Created January 14, 2014 07:33
Show Gist options
  • Save jonmorehouse/8414536 to your computer and use it in GitHub Desktop.
Save jonmorehouse/8414536 to your computer and use it in GitHub Desktop.
String manipulation using bash
# extract whats in front of extension in bash script
# name = "jon.coffee"
# echo "${name %%coffee}"
# http://tldp.org/LDP/abs/html/string-manipulation.html
# using the % / # string modifiers
# name = JonMorehouse
# remove up to the element
# remove element and print after
# echo "${name#Jon*}" --> prints Morehouse
# remove from the right side
# echo "${name%Morehouse}" --> prints Jon
# reference = http://ask.metafilter.com/80862/how-split-a-string-in-bash
# quick extension to get extensions... assumes only 1 .
# ext=${i#.*.*}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment