I have set of lines in a text file . Each set consists of 4 lines which describes about a Id,attemptID,SparkUser,starttimeEpoch and attemptID in a single file. I would like to parse and assign every FOUR lines to four variable on single shot and move on to the next set of content. I have a below script but it is not working as expected.
I am used a while loop which read every line and grep a string and assigns variable to CURL command ( A API call to spark ) . In the curl command i m having two variables which can be read only in two consective lines. If I use While loop , chances are it can assign only one variable at a time and the CURL command would expect to have two variables assigned to it , so the CURL is failing here.
while read line
do
attempt_id=`echo $line | grep -w attemptId | awk '{print $6}' | cut -d'"' -f2`
id=`echo $line| grep id | awk '{print $3}' | cut -d'"' -f2`
user=`echo $line | grep "sparkUser" | awk '{print $6}' | cut -d'"' -f2`
start_time=`echo $line | grep "startTimeEpoch" | awk '{print $9}' | cut -d'"' -f2 | cut -d',' -f1 | cut -c 1-10`
if [[ ! -z "$attempt_id" ]]
then
id=`echo $line| grep id | awk '{print $3}' | cut -d'"' -f2`
user=`echo $line | grep "sparkUser" | awk '{print $6}' | cut -d'"' -f2`
# the below variables would convert Epoch Milliseconds into Human readable time format:
#
start_time=`echo $line | grep "startTimeEpoch" | awk '{print $9}' | cut -d'"' -f2 | cut -d',' -f1 | cut -c 1-10`
time=`date -d @$start_time`
a=`curl -k -u $USERNAME:$PASS -H "Accept: application/json" -X GET -s -k http://XXXXXXXXXX:18080/history/$id/$attempt_id/environment/ | xargs | grep -Po "<tr>\K(.*?)</tr>" | sed "s/..tr.//g" | grep spark.submit.deployMode | grep -ic client`
done < wi
Sample File:
"attemptId" : "1",
"sparkUser" : "XXXXX",
"startTimeEpoch" : 1559782915432
"id" : "application_1558744311646_179708",
"attemptId" : "1",
"sparkUser" : "yyyyy",
"startTimeEpoch" : 1559782769130