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
Project3
Project4
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,
Fluke


I'm looking for some help to build an array from a text file that looks like this:
Project1
ansibleProject2
Project3
Project4
repo1Project5
repo1Project6
repo2
repo3
repo4
repo5
repo6
repo7
repo1Project7
repo2
repo3
repo4
repo5
repo6
repo7
repo8
repo9
repo10
repo1Project8
repo2
repo3
repo4
opsProject9
delete_this_repoProject10
model_serviceSo it looks like this:
c2r_service
puppetcode
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,
Fluke