Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  -1] [ 0]  / answers: 1 / hits: 9544  / 1 Year ago, sat, march 18, 2023, 4:49:01

I'm trying to write a little bash script on ubuntu 12.04 and have little experience. Odd little problem converting a text file of numbers into arrays. I need all of the first numbers, second, etc into it's own array because I'll be running computations on numbers based on column more than the line it came from. All lines are 5 integers separated by spaces with a return at the end of each line. Is a multidimensional array possible in bash? Thank you!


More From » 12.04

 Answers
4

sorry I haven’t checked back. The solution was simpler than i thought since the numbers were separated by a space with a return at the end of the lines.



#!/bin/bash
COUNT=1
while read arr1[COUNT] arr2[COUNT] arr3[COUNT] arr4[COUNT] arr5[COUNT]
do
echo "next line"
echo "${arr1[COUNT]}"
echo "${arr2[COUNT]}"
echo "${arr3[COUNT]}"
echo "${arr4[COUNT]}"
echo "${arr5[COUNT]}"
COUNT=$[$COUNT +1]
done < /home/john/testloop.txt

[#27455] Monday, March 20, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emuralm

Total Points: 290
Total Questions: 111
Total Answers: 117

Location: China
Member since Thu, Sep 1, 2022
2 Years ago
;