How can I split it so as to take every string separated with '\n' separately?
For example, as for $string1, it would be split into
string1_part1="A"
string1_part2="B"
string1_part3="C D E"
string1_part4="FG"
string1_part5="H"
i tried to do this way:
for i in $string1; do
mpla mpla
done
but this way takes spaces as separators too, so that didn't work
#!/bin/bash
## Define a string
string1="A\nB\nC D E\nFG\nH"
## Replace the \n's with a single character, since IFS
## can only be 1 character.
match='\\n'
replacement='|'
string2=$(echo ${string1//${match}/${replacement}})
## Change the input field seperator to $replacement
IFS="$replacement"
## Parse the string based on the IFS.
set -- $string2
echo "1: $1"
echo "2: $2"
echo "3: $3"
echo "4: $4"
echo "5: $5"