Answers for "shell split string by delimiter"

1

split string in shell script

IN="[email protected];[email protected]"
arrIN=(${IN//;/ })
echo ${arrIN[1]}                  # Output: [email protected]
Posted by: Guest on November-23-2021
1

split bash string

IN="[email protected];[email protected]"
arrIN=(${IN//;/ })
Posted by: Guest on April-29-2020
0

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.
Posted by: Guest on April-23-2022

Code answers related to "shell split string by delimiter"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language