我有这个文件
1.json2 - 2.json2 - 3.json2
1.json2.ml - 2.json2.ml -
ml文件示例
1.json2.ml
{"message":"Validation error","error":"validation_error",...
2.json2.ml
{"Ok":"OK":"OK"...}
我想搜索* .json2.ml是否执行帖子并保存。 如果文件存在,请检查是否存在错误,然后执行Post。
这是我用于此的代码
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://web/api/post > ${fname}.ml
else
sed '1d' ${fname}.ml | while read line
do
FS=',' read pid pname
if [ "$var" -e ""error":"validation_error"" ]
then
curl -X POST -H "Content-Type: application/json" -d @${fname} https://web/api/post > ${fname}.ml
echo que ha y $pname
fi
done
' bash
我有这个结果
syntax error near unexpected token `fi'
预期结果是什么
1 - Post 3.json2 ( file .ml no exist )
2- Post 1.json2 ( File .ml exist and have error in )
3- 2.json2 and 3.json2 ( do nothing because json2.ml is OK)
答案 0 :(得分:0)
I found the solution whit this code
else
VAR1=$(head -n 1 ${fname}.ml)
IFS="," read -ra images <<< "$VAR1"
echo que ha y $images
Thx alot to Barmar and William