Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

split string in shell script

IN="bla@some.com;john@home.com"
arrIN=(${IN//;/ })
echo ${arrIN[1]}                  # Output: john@home.com
Comment

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=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.

Comment

split sh string

#YOURSTRING="this_is_an_example"
#output:
#this
#is
#an
#example
for i in $(echo $YOURSTRING | tr "_" "
")
do
	echo $i
done
Comment

split bash string

IN="bla@some.com;john@home.com"
arrIN=(${IN//;/ })
Comment

PREVIOUS NEXT
Code Example
Shell :: linux append content of file to another linux 
Shell :: how to install julia on ubuntu 
Shell :: installing plesk on linux 
Shell :: opencv tutorial python 
Shell :: virtualbox kernel driver not installed ubuntu 
Shell :: windows edit file cmdf 
Shell :: Input is required, but Expo CLI 
Shell :: how to connect to heroku app using git remotely 
Shell :: htaccess deny all but 
Shell :: print environment variables linux 
Shell :: copy whole directory command line 
Shell :: how to find and replace on linux 
Shell :: ubuntu install terraform 
Shell :: get new instagram posts by hashtag 
Shell :: gh create github repo 
Shell :: how to uninstall unity termanl command 
Shell :: upgrade python using choco (win 10) 
Shell :: graphviz windows install 
Shell :: export bigquery scheam 
Shell :: rails aborted! TypeError: superclass mismatch for class Command 
Shell :: find bigger file on linux centos 
Shell :: liburcu ubuntu install 
Shell :: ubuntu hide home folder on desktop 
Shell :: comment in shell script 
Shell :: how to install homebrew on macos 
Shell :: start new git repo from project 
Shell :: encrypt zip password 
Shell :: git configure upstream 
Shell :: assign contents of file to variable bash 
Shell :: list user groups linux 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =