Note that there are some explanatory texts on larger screens.

plurals
  1. POConditional use of functions?
    text
    copied!<p>I created a bash script that parses ASCII files into a comma delimited output. It's worked great. Now, a new file layout for these files is being gradually introduced.</p> <p>My script has now two parsing functions (one per layout) that I want to call depending on a specific marker that is present in the ASCII file header. The script is structured thusly:</p> <pre><code>#!/bin/bash function parseNewfile() {...parse stuff...return stuff...} function parseOldfile() {...parse stuff...return stuff...} #loop thru ASCII files array i=0 while [ $i -lt $len ]; do #check if file contains marker for new layout grep CSVHeaderBox output_$i.ASC #calls parsing function based on exit code if [ $? -eq 0 ] then CXD=`parseNewfile` else CXD=`parseOldfile` fi echo ${array[$i]}| awk -v cxd=`echo $CXD` .... let i++ done&gt;&gt;${outdir}/outfile.csv ... </code></pre> <p>The script does not err out. It always calls the original function "parseOldfile" and ignores the new one. Even when I specifically feed my script with several files with the new layout. </p> <p>What I am trying to do seem very trivial. What am I missing here?</p> <p>EDIT: Samples of old and new file layouts.</p> <p>1) OLD File Layout</p> <pre><code>F779250B =====BOX INFORMATION===== Model = R15-100 Man Date = 07/17/2002 BIST Version = 3.77 SW Version = 0x122D SW Name = v1b1645 HW Version = 1.1 Receiver ID = 00089787556 =====DISK INFORMATION===== .... </code></pre> <p>2) NEW File Layout</p> <pre><code>F779250B =====BOX INFORMATION===== Model = HR22-100 Man Date = 07/17/2008 BIST Version = 7.55 SW Version = 0x066D SW Name = v18m1fgu HW Version = 2.3 Receiver ID = 028910170936 CSVHeaderBox:Platform,ManufactureDate,BISTVersion,SWVersion,SWName,HWRevision,RID CSVValuesBox:HR22-100,20080717,7.55,0x66D,v18m1fgu,2.3,028910170936 =====DISK INFORMATION===== .... </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload