AWK script automatically removing leading 0s from String
<p>I have a file BLACK.FUL.eg2:</p>

<pre><code>10&gt;BLACK.FUL&gt;272/GSMA/000000&gt;151006&gt;01
15&gt;004401074905590&gt;004401074905590&gt;B&gt;I&gt;0011&gt;Insert&gt;240/PLMN/000100&gt;&gt;5000-K525122-15
15&gt;004402145955010&gt;004402145955010&gt;B&gt;I&gt;0011&gt;Insert&gt;240/PLMN/000100&gt;&gt;1200-K108534-14
15&gt;004402146016260&gt;004402146016360&gt;B&gt;I&gt;0011&gt;Insert&gt;240/PLMN/000100&gt;&gt;1200-K-94878-14
15&gt;004402452698630&gt;004402452698630&gt;B&gt;I&gt;0011&gt;Insert&gt;240/PLMN/000100&gt;&gt;5000-K538947-14
90&gt;BLACK.FUL&gt;272/GSMA/000000&gt;151006&gt;01&gt;4
</code></pre>

<p>I've written this AWK script:</p>

<pre><code>awk 'NR &gt; 2 { print p } { p = $0 }' BLACK.FUL.eg2 | awk -F"&gt;" \
'{if (length($2) == 15) print substr($2,1,length($2)-1)","substr($3,1,length($3)-1)","$6","$8; \
else print $2","$3","$6","$8;}' | awk -F"," '{if ($2 == $1) print $1","$3","$4; \
else {if (length($1) &gt; 14) {v = substr($1,9,6); t = substr($2,9,6); \
while(v &lt;= t) print substr($2,1,8)v++substr($2,15,2)","$3","$4;} \
else {d = $1;while(d &lt;= $2) print d++","$3","$4;}}}'
</code></pre>

<p>which gives me an output of:</p>

<pre><code>00440107490559,0011,240/PLMN/000100
00440214595501,0011,240/PLMN/000100
440214601626,0011,240/PLMN/000100
440214601627,0011,240/PLMN/000100
440214601628,0011,240/PLMN/000100
440214601629,0011,240/PLMN/000100
440214601630,0011,240/PLMN/000100
440214601631,0011,240/PLMN/000100
440214601632,0011,240/PLMN/000100
440214601633,0011,240/PLMN/000100
440214601634,0011,240/PLMN/000100
440214601635,0011,240/PLMN/000100
440214601636,0011,240/PLMN/000100
00440245269863,0011,240/PLMN/000100
</code></pre>

<p>with one problem: the leading 0s of strings in field1, are automatically getting removed due to a numeric operation on them. So my actual expected output is:</p>

<pre><code>00440107490559,0011,240/PLMN/000100
00440214595501,0011,240/PLMN/000100
00440214601626,0011,240/PLMN/000100
00440214601627,0011,240/PLMN/000100
00440214601628,0011,240/PLMN/000100
00440214601629,0011,240/PLMN/000100
00440214601630,0011,240/PLMN/000100
00440214601631,0011,240/PLMN/000100
00440214601632,0011,240/PLMN/000100
00440214601633,0011,240/PLMN/000100
00440214601634,0011,240/PLMN/000100
00440214601635,0011,240/PLMN/000100
00440214601636,0011,240/PLMN/000100
00440245269863,0011,240/PLMN/000100
</code></pre>

<p>For that I'm trying the below updated AWK script:</p>

<pre><code>awk 'NR &gt; 2 { print p } { p = $0 }' BLACK.FUL.eg2 | awk -F"&gt;" \
'{if (length($2) == 15) print substr($2,1,length($2)-1)","substr($3,1,length($3)-1)","$6","$8; \
else print $2","$3","$6","$8;}' | awk -F"," '{if ($2 == $1) print $1","$3","$4; \
else {if (length($1) &gt; 14) {v = substr($1,9,6); t = substr($2,9,6); \
while(v &lt;= t) print substr($2,1,8)v++substr($2,15,2)","$3","$4;} \
else {d = $1; for ( i=1;i&lt;length($1);i++ ) if (substr($1,i++,1) == "0") \
{m=m"0"; else exit 1;}; while(d &lt;= $2) print md++","$3","$4;}}}'
</code></pre>

<p>But getting an error:</p>

<pre><code>awk: cmd. line:4: {m=m"0"; else exit 1;}; while(d &lt;= $2) print   md++","$3","$4;}}}
awk: cmd. line:4:          ^ syntax error
</code></pre>

<p>Can you please highlight what I'm doing wrong to achieve the expected output. Modification only for my already existing AWK script will be of much help. Thanks</p>

<p>NOTE: The Leading 0s can be of any number of occcurence, not only 2 0s in every case as in the above example outputs.</p>