string="you got a friend in me"
IFS=' ' read -ra split <<< "$string"
echo "${split[*]}"
# Output: you got a friend in me
echo "${split[3]}"
# Output: friend
IN="bla@some.com;john@home.com"
arrIN=(${IN//;/ })
echo ${arrIN[1]} # Output: john@home.com
#!/usr/bin/env bash
# There are different method of splitting a string.
# Two of those methods are shown below
# a sample string delimeted by ";"
IN="FirstName=John; LastName=Doe; Email=jd@someone.com"
# First method:
# splits the string on ';' and puts them into an array
person=$(echo $IN | tr ";" "
")
# you can loop through the array
for info in $person
do
echo "> [$info]"
done
# Second method:
echo "$IN" | cut -d ";" -f 1 # returns the first part
echo "$IN" | cut -d ";" -f 2 # returns the second part
#and so on.
#YOURSTRING="this_is_an_example"
#output:
#this
#is
#an
#example
for i in $(echo $YOURSTRING | tr "_" "
")
do
echo $i
done
IN="bla@some.com;john@home.com"
arrIN=(${IN//;/ })
$ s='one_two_three_four_five'
$ A="$(cut -d'_' -f2 <<<"$s")"
$ echo "$A"
two
$ B="$(cut -d'_' -f4 <<<"$s")"
$ echo "$B"
four