@kenanhancer/

BashStringSplit

bash

No description

fork
loading
Files
  • main.sh
  • pathFile.txt
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
echo Hello World

echo "a b c d e" | tr ' ' '\n'

tr " " '\n' <<< 'a b c d e'

echo 'a b c d e' | sed -e 's/ /\n/g'

tr ';' '\n' < pathFile.txt

tr ';' '\n' <<< $(<pathFile.txt)

#read from file
echo $(<pathFile.txt)

cat pathFile.txt

echo

read first second <<< "hello world"

echo $second $first

echo "merhaba dunya" | read third forth

echo $forth $third

#string split and create array
IFS=':' read -a field <<< "1:2:3:4:5"

echo ${field[0]} ${field[1]}


str='a;b;c;d;e;f;g'
for x in `echo $str | tr ";" "\n"`; do echo $x; done