Im not able to fetch data of variables using for loop in Shell script ksh
<p>Now I have the code to work on this file type:
cat myfile.txt</p>

<pre><code>XSAP_SM1_100 COR-REV-SAPQ-P09 - 10/14/2013 -
SCHEDULE XSAP_SM1_100#COR-REV-SAPQ-P09 TIMEZONE Europe/Paris
ON RUNCYCLE RULE1 "FREQ=WEEKLY;BYDAY=WE"
EXCEPT RUNCYCLE CALENDAR2 FR1DOFF -1 DAYS
EXCEPT RUNCYCLE SIMPLE3 11/11/2011
AT 0530
:
XSAP_SM1_100#CORREVSAPQP09-01
AT 0640 TIMEZONE Europe/Paris
XSAP_SM1_100#CORREVSAPQP09-02
AT 0645 TIMEZONE Europe/Paris
</code></pre>

<p>Code is</p>

<pre><code>awk 'BEGIN { RS=":"; FS="\n"}
    NR==2 {
        for(i=1;i&lt;=NF;++i) {
            if($i !~ /^$/) {
                split($i,tmp,"#")
                i=i+1
                split($i,tmp2," ")
                printf "\"%s\",\"%s\",\"%s\"\n", tmp[1],tmp[2],tmp2[2]
            }
        }
    }'
</code></pre>

<p>But I have another file type i.e.I'll be executing this command to 1000s of files in for loop but as of I have consolidated and only for below type it's not working as expected.</p>

<pre><code>] cat testing.txt
ODSSLT_P09 COR-ODS-SMT9-B01 - 12/29/2015 -
SCHEDULE ODSSLT_P09#COR-ODS-SMT9-B01 TIMEZONE UTC
ON RUNCYCLE RULE1 "FREQ=DAILY;"
AT 0505
PRIORITY 11
:
ODSSLT_P09#CORODSSMT9001-01
UNTIL 2355 TIMEZONE Asia/Shanghai
EVERY 0100
ODSSLT_P09#CORODSSMT9001-02
AT 2355
EVERY 0100
ODSSLT_P09#CORODSSMT9001-03
ODSSLT_P09#CORODSSMT9001-04
UNTIL 2355 TIMEZONE Asia/Shanghai
EVERY 0100

EOF
</code></pre>

<p>Expected output for this file:</p>

<pre><code>"ODSSLT_P09","CORODSSMT9001-01",""
"ODSSLT_P09","CORODSSMT9001-02","2355"
"ODSSLT_P09","CORODSSMT9001-03",""
"ODSSLT_P09","CORODSSMT9001-04",""
</code></pre>

<p>Actual output from the code is </p>

<pre><code>| grep -v -i -w -E 
"CONFIRMED|DEADLINE|DAY|DAYS|EVERY|NEEDS|OPENS|PRIORITY|PROMPT|UNTIL|AWSBIA291I|END|FOLLOWS" |
awk 'BEGIN { RS=":"; FS="\n"}
NR==2 {for(i=1;i&lt;=NF;++i) {
  if($i !~ /^$/) {
    split($i,tmp,"#")
    i=i+1
    split($i,tmp2," ")
    printf "\"%s\",\"%s\",\"%s\"\n", tmp[1],tmp[2],tmp2[2]
}}}'
</code></pre>

<p>output just gives:</p>

<pre><code>"ODSSLT_P09","CORODSSMT9001-01",""
"AT 2355","",""
"ODSSLT_P09","CORODSSMT9001-04",""
</code></pre>