Find file json check if generated or execute
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I want to find *.json2 files , check if they r executed if no execute POST.
I have
1.json2
2.json2 2.json2.ml
3.json2 3.json2.ml
I use this command
find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;
I want to execute only the file dont have ml extension.
Thx
scripting find json
add a comment |Â
up vote
1
down vote
favorite
I want to find *.json2 files , check if they r executed if no execute POST.
I have
1.json2
2.json2 2.json2.ml
3.json2 3.json2.ml
I use this command
find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;
I want to execute only the file dont have ml extension.
Thx
scripting find json
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to find *.json2 files , check if they r executed if no execute POST.
I have
1.json2
2.json2 2.json2.ml
3.json2 3.json2.ml
I use this command
find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;
I want to execute only the file dont have ml extension.
Thx
scripting find json
I want to find *.json2 files , check if they r executed if no execute POST.
I have
1.json2
2.json2 2.json2.ml
3.json2 3.json2.ml
I use this command
find . -type f -name '*.json2' | if [.ml]; then -exec sh -c 'curl -X POST -H "Content-Type: application/json" -d @ https://api.myweb.com/api > .ml' ;
I want to execute only the file dont have ml extension.
Thx
scripting find json
scripting find json
edited Aug 29 at 10:13
Jeff Schaller
32.7k849110
32.7k849110
asked Aug 29 at 2:37
Jess
83
83
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
-1
down vote
accepted
Have you considered using xargs
?
find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash
As for that trailing bash
, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.
It's not a trick, it's that argument that gets put into$0
.
â Kusalananda
Aug 29 at 10:17
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
add a comment |Â
up vote
0
down vote
find . -type f -name '*.json2' -exec sh -c '
for pathname; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done' sh +
This would find all regular files whose filenames match the pattern *.json2
in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find
, whether there's a .ml
file corresponding to the pathname. If there is not, your curl
command is executed.
This could be simplified into the following if all files are located in the current directory only:
for pathname in ./*.json2; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done
Note that this is essentially exactly the same loop as in the script called by find
. The only difference is that in the first example, find
act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).
Related:
- Understanding the -exec option of `find`
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
-1
down vote
accepted
Have you considered using xargs
?
find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash
As for that trailing bash
, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.
It's not a trick, it's that argument that gets put into$0
.
â Kusalananda
Aug 29 at 10:17
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
add a comment |Â
up vote
-1
down vote
accepted
Have you considered using xargs
?
find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash
As for that trailing bash
, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.
It's not a trick, it's that argument that gets put into$0
.
â Kusalananda
Aug 29 at 10:17
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
add a comment |Â
up vote
-1
down vote
accepted
up vote
-1
down vote
accepted
Have you considered using xargs
?
find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash
As for that trailing bash
, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.
Have you considered using xargs
?
find . -type f -name '*.json2' | xargs bash -c 'for fname; do if [ ! -e $fname.ml ]; then curl -X POST -H "Content-Type: application/json" -d @$fname https://api.myweb.com/api > $fname.ml; fi; done' bash
As for that trailing bash
, it's a 'trick' I just learned on the xargs wikipedia page. (It has to be there or the first argument isn't processed.)
I admit I'd never used that before, but I did test it with an echo command and some test files, and it seems to do what you want.
answered Aug 29 at 3:38
flaysomerages
1225
1225
It's not a trick, it's that argument that gets put into$0
.
â Kusalananda
Aug 29 at 10:17
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
add a comment |Â
It's not a trick, it's that argument that gets put into$0
.
â Kusalananda
Aug 29 at 10:17
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
It's not a trick, it's that argument that gets put into
$0
.â Kusalananda
Aug 29 at 10:17
It's not a trick, it's that argument that gets put into
$0
.â Kusalananda
Aug 29 at 10:17
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
I explained that; I called it a trick following the reference I gave. Why was my answer downvoted? It follows the basic pattern laid out by the OP, it is concise and SFAIK (I can't test their curl command) it works.
â flaysomerages
Aug 29 at 13:44
add a comment |Â
up vote
0
down vote
find . -type f -name '*.json2' -exec sh -c '
for pathname; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done' sh +
This would find all regular files whose filenames match the pattern *.json2
in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find
, whether there's a .ml
file corresponding to the pathname. If there is not, your curl
command is executed.
This could be simplified into the following if all files are located in the current directory only:
for pathname in ./*.json2; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done
Note that this is essentially exactly the same loop as in the script called by find
. The only difference is that in the first example, find
act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).
Related:
- Understanding the -exec option of `find`
add a comment |Â
up vote
0
down vote
find . -type f -name '*.json2' -exec sh -c '
for pathname; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done' sh +
This would find all regular files whose filenames match the pattern *.json2
in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find
, whether there's a .ml
file corresponding to the pathname. If there is not, your curl
command is executed.
This could be simplified into the following if all files are located in the current directory only:
for pathname in ./*.json2; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done
Note that this is essentially exactly the same loop as in the script called by find
. The only difference is that in the first example, find
act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).
Related:
- Understanding the -exec option of `find`
add a comment |Â
up vote
0
down vote
up vote
0
down vote
find . -type f -name '*.json2' -exec sh -c '
for pathname; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done' sh +
This would find all regular files whose filenames match the pattern *.json2
in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find
, whether there's a .ml
file corresponding to the pathname. If there is not, your curl
command is executed.
This could be simplified into the following if all files are located in the current directory only:
for pathname in ./*.json2; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done
Note that this is essentially exactly the same loop as in the script called by find
. The only difference is that in the first example, find
act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).
Related:
- Understanding the -exec option of `find`
find . -type f -name '*.json2' -exec sh -c '
for pathname; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done' sh +
This would find all regular files whose filenames match the pattern *.json2
in or below the current directory. For batches of these files, a short shell script is executed. This script tests, for each pathname given to it by find
, whether there's a .ml
file corresponding to the pathname. If there is not, your curl
command is executed.
This could be simplified into the following if all files are located in the current directory only:
for pathname in ./*.json2; do
[ -e "$pathname.ml" ] && continue
curl -X POST -H "Content-Type: application/json" -d @"$pathname" https://api.myweb.com/api >"$pathname.ml"
done
Note that this is essentially exactly the same loop as in the script called by find
. The only difference is that in the first example, find
act as a pathname generator for the loop, while in the shorter example, the pathnames are generated using a globbing pattern (and only from the current directory).
Related:
- Understanding the -exec option of `find`
answered Aug 29 at 12:37
Kusalananda
107k14209329
107k14209329
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465411%2ffind-file-json-check-if-generated-or-execute%23new-answer', 'question_page');
);
Post as a guest
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
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
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