Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Last edited by flukeyLinux; 03-20-2020 at 10:30 AM.
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?
this is purely dynamically being done. so you're going to have to come up with a way to keep track of each array created dynamically and keep track of there names in another array perhaps.
just using that "file" you posted.
Code:
#!/bin/bash
arr=''
while read a ;
do
#echo $a
if [[ "${a,,}" =~ "project" ]] ;
then
#keep which project it is
arr=$a
#to add in the print out of each
#array created, but not kept.
#because it is being over written by
#the next projectX in line within
#the 'data' file.
echo "$arr"
#if projects hits then the next
#step is to get the repo's if any.
elif [[ "${a,,}" =~ "repo" ]] ;
then
echo "$a"
arr+=("$a")
fi
done < data
this is purely dynamically being done. so you're going to have to come up with a way to keep track of each array created dynamically and keep track of there names in another array perhaps.
just using that "file" you posted.
Code:
#!/bin/bash
arr=''
while read a ;
do
#echo $a
if [[ "${a,,}" =~ "project" ]] ;
then
#keep which project it is
arr=$a
#to add in the print out of each
#array created, but not kept.
#because it is being over written by
#the next projectX in line within
#the 'data' file.
echo "$arr"
#if projects hits then the next
#step is to get the repo's if any.
elif [[ "${a,,}" =~ "repo" ]] ;
then
echo "$a"
arr+=("$a")
fi
done < data
it is just an idea, work in progress. but I'd think it is still all being done dynamically regardless of what tools you use.
This would do actually but most repo's don't have the word repo in it. I am going to try going the JQ route but if I don't get what I need, I will be coming back to this.
I strip out the 1t column with awk and remove any white space with tr -d.
I then use a for loop to get the repo's under every project with an API call
# Get repos for every project
for i in `cat projectkeys.txt`;
do echo $i;
curl -s -u $LOGIN "https://$SERVER/rest/api/1.0/projects/$i/repos?limit=10" -k | jq . | grep "slug";
done > projectkeys2.txt
I couldn't do this with quotes and commas so that is why I removed them.
That's not JSON though. Is that really how the source data looks? Please provide an exact sample of the format, sanitized if necessary but retaining the format nonetheless.
That's not JSON though. Is that really how the source data looks? Please provide an exact sample of the format, sanitized if necessary but retaining the format nonetheless.
true, I use grep to get what I need. Here is the full output of the API call
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.