Hi
I would like to have a function in .bashrc that would split a string into substrings (according to given separator) and to return a given substring. Something like:
function splitString() {
#echo $1;
awk -v name=$1 -v sep=$2 -v field=$3 'BEGIN{split(name,a,sep); print a[field]}'
return a[$3]
}
usage would be like:
splitString "peca_is_stupid" "_" 3
with result:
"stupid"
How to return "stupid" from this function to be further usable in the main script that use splitString() function?
thanx
peca
I would like to have a function in .bashrc that would split a string into substrings (according to given separator) and to return a given substring. Something like:
function splitString() {
#echo $1;
awk -v name=$1 -v sep=$2 -v field=$3 'BEGIN{split(name,a,sep); print a[field]}'
return a[$3]
}
usage would be like:
splitString "peca_is_stupid" "_" 3
with result:
"stupid"
How to return "stupid" from this function to be further usable in the main script that use splitString() function?
thanx
peca