Created
May 11, 2018 22:10
-
-
Save blizzrdof77/6867f6cbdff9acfb15875430ba724f20 to your computer and use it in GitHub Desktop.
Split a string simple bash function
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
#!/bin/bash | |
# Split a string returning the specified index (or 2nd instance by default) | |
if [ -z "$1" ] || [ -z "$2" ]; then | |
echo "Provide split delimiter and string" | |
else | |
delim="$1" | |
string="$2" | |
if [ -z "$3" ]; then | |
split_index=2 | |
else | |
split_index="$3" | |
fi | |
echo "$2" | cut -d$1 -f $split_index | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment