Created
January 14, 2014 07:33
-
-
Save jonmorehouse/8414536 to your computer and use it in GitHub Desktop.
String manipulation using bash
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
# 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