Unable to print block of data

Hi All,

Iam unable to print the below block and getting the error.Can anyone please help me in this.

 Input Data
eaits001z$ echo "-------LINENO_JOBID_VAL--------${LINENO_JOBID_VAL}---"
-------LINENO_JOBID_VAL--------58167|253473 58169|253473 58171|253473 58179|253473 58180|253473 58181|257311 58183|257311 58185|257311 58187|257311 58192|257311 58196|263935 58198|263935 58200|263935 58202|263935 58207|263935 58211|264359 58212|264360 58215|264360 58217|264360 58219|264360 58227|264360 58229|264360 58230|264487 58231|264488 58234|264488 58236|264488 58238|264488 58246|264488 58248|264488 58249|286343 58251|286343 58253|286343 58255|286343 58260|286343 58264|286469 58266|286469 58268|286469 58270|286469 58275|286469 58279|287226 58281|287226 58283|287226 58285|287226 58290|287226 58294|287351 58296|287351 58298|287351 58300|287351 58305|287351 58309|292485 58311|292485 58313|292485 58315|292485 58320|292485 58324|292754 58326|292754 58328|292754 58330|292754 58335|292754 58339|293116 58341|293116 58343|293116 58345|293116 58350|293116 58354|293150 58356|293150 58358|293150 58360|293150 58365|293150 58369|293207 58371|293207 58373|293207 58375|293207 58380|293207 58384|293241 58386|293241 58388|293241 58390|293241 58395|293241 58399|293486 58401|293486 58403|293486 58405|293486 58410|293486 58414|293501 58416|293501 58418|293501 58420|293501 58425|293501 58429|293521 58431|293521 58433|293521 58435|293521 58440|293521 58444|298297 58446|298297 58448|298297 58450|298297 58455|298297 58459|299130 58461|299130 58463|299130 58465|299130 58470|299130 58474|299428 58476|299428 58478|299428 58480|299428 58485|299428 58489|304171 58491|304171 58493|304171 58495|304171 58500|304171 58504|306320 58506|306320 58508|306320 58510|306320 58515|306320 58519|321170 58521|321170 58523|321170 58525|321170 58530|321170 58534|329122 58536|329122---

Script
for (i=0;i<${#LINENO_JOBID_VAL[@]};i++)
do
      STARTPT=`echo ${LINENO_JOBID_VAL[$i]}|cut -d"|" -f1`
   ENDPT=`echo ${LINENO_JOBID_VAL[$i]}|cut -d"|" -f2`
   if [ ${STARTPT} != "" ] && [ ${ENDPT} == "EOF" ]
   then
     echo "IN SUCCESS CONDITION--"$STARTPT
     nawk -v STPT=$STARTPT 'NR >= STPT { print $0} ' ${BASEPATH}/$FILE|nawk '{ if (match($0,"^[0-9][0-9][0-9][0-9] [A-Z][a-z][a-z] [0-9][0-9]")){ if ($0 !~ /Job-'$MAX_JOB'/) {exit; }else {  print $0; }} print $0}' 
   else
     echo "IN FAILED CONDITION--"$STARTPT"|"$ENDPT
     nawk -v STPT=$STARTPT EDPT=$ENDPT 'NR==STPT,NR==EDPT { print $0} ' ${BASEPATH}/$FILE 
   fi
done

What is your aim ? what's error message ?

Hi, Sorry for not being clear. I want to make a dynamic loop for the values in "LINENO_JOBID_VAL" using space as delimiter and the separate the field 1(start point) and field 2 (end point) and do the printing logic. I tried with referring some older posts but it is not helping and when I include the below piece in my shell iam getting the below error. Hence not sure how I make a dynamic loop and use it as array.

test.sh: syntax error at line 140: `(' unexpected

which is the for loop in our case..
FYI..Iam using solaris 10 box.

correct like this, and try

for(( i=0; i<${#LINENO_JOBID_VAL[@]}; i++ ))

Hi Akshay,

Thanks for the suggestion.However it worked when I ran separately..But when I use the same piece of code in shell.It's not working and getting the same error as above

test.sh: syntax error at line 140: `(' unexpected

No clue why iam getting it..

FYI. Iam using the bash mode.

Regards,
Kumar

show your code, I can't see what's there in 140th line

Hi Akshay,

Please use the below input to simulate the issue.

Input
------------------
2014 Jan 14 15:12:43:460 GMT +0 BW.Folder-Process_Archive Debug [BW-User] RequestMessage Job-329121 [Services/Peoplesoft/AcV_Add/Interface/SourceRequest.process/Activate/LogEntry]: <ActivityOutput><sendSubject>TEST.GT.TTT.PS.Request._Null_.asasasa.1</sendSubject><replySubject>_INBOX.C0A8F848.24CE52D3CE5F15FB9E0.1</replySubject><certifiedSequenceNumber>0</certifiedSequenceNumber><body><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^pfmt^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">10</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^ver^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">30</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^type^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^encoding^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^tracking^</ns0:name><ns0:id>0</ns0:id><ns0:msg><ns0:field><ns0:name>^id^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"
ttttttttttttttttttttttttttttttttttasasaaaaaaaaaaaaaaaaaaaaa
asaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbdsdsdsdsdsdssssssssssssssssssssssssssssssssd
2014 Jan 14 15:12:43:460 GMT +0 BW.Folder-Process_Archive Debug [BW-User] RequestMessage Job-329122 [Services/Peoplesoft/AcV_Add/Interface/SourceRequest.process/Activate/LogEntry]: <ActivityOutput><sendSubject>TEST.GT.TTT.PS.Request._Null_.asasasa.1</sendSubject><replySubject>_INBOX.C0A8F848.24CE52D3CE5F15FB9E0.1</replySubject><certifiedSequenceNumber>0</certifiedSequenceNumber><body><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^pfmt^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">10</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^ver^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">30</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^type^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^encoding^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^tracking^</ns0:name><ns0:id>0</ns0:id><ns0:msg><ns0:field><ns0:name>^id^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"
asasssssssssssssssssssssasasasa
asaaaaaaaaaaaaaaaaaaa
#!/bin/bash

BASEPATH="/opt/tibco/logs/bw/EAI_Automation"

FILE="Input.log"
echo "File name::${FILE}" 

STARTPT_ENDPT_VAL="5|EOF"

echo "-------STARTPT_ENDPT_VAL--------${STARTPT_ENDPT_VAL}---"

########################################################
#Printing The Final set using different awk methods
########################################################

for(( i=0; i<${#STARTPT_ENDPT_VAL[@]}; i++ ))
do
      STARTPT=`echo ${STARTPT_ENDPT_VAL[$i]}|cut -d"|" -f1`
   ENDPT=`echo ${STARTPT_ENDPT_VAL[$i]}|cut -d"|" -f2`
   if [ ${STARTPT} != "" ] && [ ${ENDPT} == "EOF" ]
   then
     echo "IN SUCCESS CONDITION--"$STARTPT
     nawk -v STPT=$STARTPT 'NR >= STPT { print $0} ' ${BASEPATH}/$FILE 
   else
     echo "IN FAILED CONDITION--"$STARTPT"|"$ENDPT
     nawk 'NR=='${STARTPT}',NR=='${ENDPT}' { print "$0} ' ${BASEPATH}/${FILE}
   fi
done

echo "###############################Print Ends###############################################"
done
Error log
------------------------
bsss001z$ sh test_script.sh
File name::Input.log
***********MAXIMUM JOBID**********329122
-------STARTPT_ENDPT_VAL--------5|EOF---
test_script.sh: syntax error at line 16: `(' unexpected
Expected Output--If we run the commands separately
---------------------------------------------------------------------------
IN SUCCESS CONDITION--5
2014 Jan 14 15:12:43:460 GMT +0 BW.Folder-Process_Archive Debug [BW-User] RequestMessage Job-329122 [Services/Peoplesoft/AcV_Add/Interface/SourceRequest.process/Activate/LogEntry]: <ActivityOutput><sendSubject>TEST.GT.TTT.PS.Request._Null_.asasasa.1</sendSubject><replySubject>_INBOX.C0A8F848.24CE52D3CE5F15FB9E0.1</replySubject><certifiedSequenceNumber>0</certifiedSequenceNumber><body><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^pfmt^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">10</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^ver^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">30</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^type^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^encoding^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">1</ns0:simple></ns0:field><ns0:field xmlns:ns0="http://xmlns.tibco.com/2003/5/bw/plugins/tibrv"><ns0:name>^tracking^</ns0:name><ns0:id>0</ns0:id><ns0:msg><ns0:field><ns0:name>^id^</ns0:name><ns0:id>0</ns0:id><ns0:simple xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"
asasssssssssssssssssssssasasasa
asaaaaaaaaaaaaaaaaaaa

---------- Post updated 01-21-14 at 06:24 AM ---------- Previous update was 01-20-14 at 12:47 PM ----------

Hi, Can anyone help me for the above issue since I got struck at the last step and need your assistance please.

Regards,
Kumar.

done unexpected

Hi Akshay,

I don't see any issue in the extra done statement and getting the same error.

regards,
Kumar.

---------- Post updated 01-22-14 at 04:55 AM ---------- Previous update was 01-21-14 at 08:32 AM ----------

Hi, Can anyone have a look at it and help me..Your immediate help will be appreciated.

Regards,
Kumar.

---------- Post updated at 12:11 PM ---------- Previous update was at 04:55 AM ----------

Hi All,

After the long struggle I got to know that the unexpected error is due to the bash version..

I have refer the old post and got the answer.

Looping through arrays | Unix Linux Forums | Shell Programming and Scripting

My next blocker is how to define the arrays using any delimiters..Kindly mind that the values are dynamic..
In the below example the space is the delimiter and I need the loop to run 4 times..But it is not working..Any clue will be highly appreciated.

VAR="5|EOF 89|840 45|454 45|454"
echo "***********VAR**********----${#VAR[*]}----"

cnt=0
while [ $cnt -lt ${#VAR[*]} ]
do
echo "$cnt--${VAR[$cnt]}"
      cnt=$(( $cnt + 1 ))
done
Output
0--5|EOF 89|840 45|454 45|454

Hi All,
A simple for loop helped me. Please see below

VAL="567|32 3434|3223 4545|343"
for i in $VAL
do   
   STARTPT=`echo $i|cut -d"|" -f1`
   ENDPT=`echo $i|cut -d"|" -f2`
   if [ ${STARTPT} != "" ] && [ ${ENDPT} == "EOF" ]
   then
     echo "IN SUCCESS CONDITION--"$STARTPT
   else
     echo "IN FAILED CONDITION--"$STARTPT"|"$ENDPT
    fi
done