I have a text file that looks like so:
:SomeWord:::SomeOtherWord:::MaybeAnotherWord::
Assuming that I don't know how many ":" are between words or even how many words there are, but every word is after a ":", I want to take this text file in Linux terminal and set 2 local vars to the first and second word found.
I have tried to make an array from the text file and then grab the 0 and 1 indexes but it didn't work like I thought.
~# myarray=$(cat mytextfile.txt | tr ":" "\n")
~# for line in $myarray ; do echo "[$line]"; done
[SomeWord]
[SomeOtherWord]
[MaybeAnotherWord]
ok that looks like it worked but then when I try to grab by index I get unexpected results..
~# echo ${myarray[0]}
SomeWord SomeOtherWord MaybeAnotherWord
~# echo ${myarray[1]}
~#
I don't know if I'm splitting the file wrong?