split string and create array bash
my_array=($(echo $string | tr "," "\n"))
split string and create array bash
my_array=($(echo $string | tr "," "\n"))
split string in shell
#!/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 protected]"
# First method:
# splits the string on ';' and puts them into an array
person=$(echo $IN | tr ";" "\n")
# 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.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us