Finding all the JSONS file in directory and combining it in array in bash
up vote
2
down vote
favorite
i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data
I am trying this
find . -name *data.json | tee result.json
It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result
this command is saving a result.json file which look like this
./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json
linux bash find command
New contributor
add a comment |
up vote
2
down vote
favorite
i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data
I am trying this
find . -name *data.json | tee result.json
It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result
this command is saving a result.json file which look like this
./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json
linux bash find command
New contributor
It's not clear to me what you wantresult.json
to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
– ruakh
3 hours ago
yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago
Could you not just save the results fromfind
into an array?
– RoadRunner
2 hours ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data
I am trying this
find . -name *data.json | tee result.json
It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result
this command is saving a result.json file which look like this
./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json
linux bash find command
New contributor
i wanna find all the json files file specific directory and combine it one parent result that will contain all the result data
I am trying this
find . -name *data.json | tee result.json
It is finding all the data but it is saving its path in result.json,how can i get the data inside all the file and get a combine JSON of all result
this command is saving a result.json file which look like this
./17-10-2018/ghatkopar/17-18/data.json
./17-10-2018/ghatkopar/18-19/data.json
./17-10-2018/ghatkopar/10-11/data.json
./17-10-2018/ghatkopar/11-12/data.json
./17-10-2018/ghatkopar/15-16/data.json
./17-10-2018/ghatkopar/19-20/data.json
./17-10-2018/ghatkopar/14-15/data.json
./17-10-2018/ghatkopar/12-13/data.json
./17-10-2018/ghatkopar/20-21/data.json
./17-10-2018/mulund-west/16-17/data.json
./17-10-2018/mulund-west/21-22/data.json
./17-10-2018/mulund-west/13-14/data.json
./17-10-2018/mulund-west/data.json
./17-10-2018/mulund-west/17-18/data.json
./17-10-2018/mulund-west/18-19/data.json
./17-10-2018/mulund-west/10-11/data.json
./17-10-2018/mulund-west/11-12/data.json
./17-10-2018/mulund-west/15-16/data.json
./17-10-2018/mulund-west/19-20/data.json
./17-10-2018/mulund-west/14-15/data.json
./17-10-2018/mulund-west/12-13/data.json
./17-10-2018/mulund-west/20-21/data.json
./17-10-2018/bhandup/16-17/data.json
./17-10-2018/bhandup/21-22/data.json
./17-10-2018/bhandup/13-14/data.json
./17-10-2018/bhandup/data.json
./17-10-2018/bhandup/17-18/data.json
./17-10-2018/bhandup/18-19/data.json
./17-10-2018/bhandup/10-11/data.json
./17-10-2018/bhandup/11-12/data.json
./17-10-2018/bhandup/15-16/data.json
linux bash find command
linux bash find command
New contributor
New contributor
edited 3 hours ago
New contributor
asked 3 hours ago
Anurag Mishra
112
112
New contributor
New contributor
It's not clear to me what you wantresult.json
to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
– ruakh
3 hours ago
yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago
Could you not just save the results fromfind
into an array?
– RoadRunner
2 hours ago
add a comment |
It's not clear to me what you wantresult.json
to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?
– ruakh
3 hours ago
yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago
Could you not just save the results fromfind
into an array?
– RoadRunner
2 hours ago
It's not clear to me what you want
result.json
to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?– ruakh
3 hours ago
It's not clear to me what you want
result.json
to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?– ruakh
3 hours ago
yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago
yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago
Could you not just save the results from
find
into an array?– RoadRunner
2 hours ago
Could you not just save the results from
find
into an array?– RoadRunner
2 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You need to cat
each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:
#! /bin/bash
printf [
separator=""
find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
printf $separator
separator=,
cat "$j"
done
printf ]
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You need to cat
each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:
#! /bin/bash
printf [
separator=""
find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
printf $separator
separator=,
cat "$j"
done
printf ]
add a comment |
up vote
0
down vote
You need to cat
each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:
#! /bin/bash
printf [
separator=""
find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
printf $separator
separator=,
cat "$j"
done
printf ]
add a comment |
up vote
0
down vote
up vote
0
down vote
You need to cat
each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:
#! /bin/bash
printf [
separator=""
find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
printf $separator
separator=,
cat "$j"
done
printf ]
You need to cat
each file, not output its name. You also need to output a comma before each json except the first one, and the enclosing square brackets:
#! /bin/bash
printf [
separator=""
find . -name '*data.json' -print0 | while IFS= read -d '' -r j ; do
printf $separator
separator=,
cat "$j"
done
printf ]
answered 3 hours ago
choroba
151k14138199
151k14138199
add a comment |
add a comment |
Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Anurag Mishra is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370494%2ffinding-all-the-jsons-file-in-directory-and-combining-it-in-array-in-bash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It's not clear to me what you want
result.json
to contain; there are many different ways to combine many JSON values into a single value. Do you just want them wrapped in an array?– ruakh
3 hours ago
yeah,i wanna wrap it in array
– Anurag Mishra
3 hours ago
Could you not just save the results from
find
into an array?– RoadRunner
2 hours ago