Article 510MM Creating an array from a txt file in bash

Creating an array from a txt file in bash

by
flukeyLinux
from LinuxQuestions.org on (#510MM)
Hi all,
I'm looking for some help to build an array from a text file that looks like this:

Project1
ansible
Project2
Project3
Project4
repo1
Project5
repo1
repo2
repo3
repo4
repo5
repo6
repo7
Project6
repo1
repo2
repo3
repo4
repo5
repo6
repo7
repo8
repo9
repo10
Project7
repo1
repo2
repo3
repo4
Project8
ops
Project9
delete_this_repo
Project10
model_service
c2r_service
puppetcode
So it looks like this:

Project1=(ansible)
Project2=()
Project3=()
Project4=(repo1)
Project5=(repo1 repo2 repo3 repo4 repo5 repo6 repo7)
... and so on.

Anything that does not have a "repo" can just be deleted. That could be done before or after. I tried looking into "declare" but I am not sure how to use it. Maybe there is something with awk I could use?

This data was in jq but I removed all of the double quotes and commas to get the data I needed to look like it does above. But maybe there is an easier way to do this using jq?

Any suggestions welcome!

Thanks in advance,
Flukelatest?d=yIl2AUoC8zA latest?i=JOUIHLQE54E:QEVLM_MmSVI:F7zBnMy latest?i=JOUIHLQE54E:QEVLM_MmSVI:V_sGLiP latest?d=qj6IDK7rITs latest?i=JOUIHLQE54E:QEVLM_MmSVI:gIN9vFwJOUIHLQE54E
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments