“Split String in Shell” Code-Antworten

Split SH String

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

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.

Mckynde

Bash -Split -Variable durch Trennzeichen

IFS='|' read -r -a arrayName <<< "$variable"
C0W

Split -Zeichenfolge mit Linux CMD geteilt

$ s='one_two_three_four_five'

$ A="$(cut -d'_' -f2 <<<"$s")"
$ echo "$A"
two

$ B="$(cut -d'_' -f4 <<<"$s")"
$ echo "$B"
four
Envious Emu

Ähnliche Antworten wie “Split String in Shell”

Fragen ähnlich wie “Split String in Shell”

Weitere verwandte Antworten zu “Split String in Shell” auf Shell/Bash

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen