0

I have file HOMO.txt with this content:

   1506      -4.6242      2.00000

I am using below commands:

$ mapfile -t myArray < HOMO.txt
$ echo ${myArray[0]} 
1506 -4.6242 2.00000
$ echo ${myArray[1]}

The last command is returning a blank line. What I want is, to assign the middle value to a variable. Can anybody please suggest a fix.

Léa Gris
  • 17,497
  • 4
  • 32
  • 41

1 Answers1

0

By default mapfile uses newline as element delimiter. You can change it to space " " with the -d option like follows.

mapfile -t -d " " myArray < HOMO.txt
echo ${myArray[0]}
echo ${myArray[1]}

# Output
1506
-4.6242
schilli
  • 1,700
  • 1
  • 9
  • 17