title: bash script : end of line character issue : file from excel
body: <p>Working in bash under Linux ubuntu 10 here</p>
  
  <p>I have Bash script that reads lines from gedit-created .txt file and pushes then into an array. Works as expected.</p>
  
  <p>However when my input is a .txt generated from Excel it throws the error </p>
  
  <pre><code>")syntax error: invalid arithmetic operator (error token is "
  
  echo -n $elem | od -x yields
  0000000 3533 0d32
  0000004
  </code></pre>
  
  <p>I can't help feeling I'm <em>almost</em> at the solution, but it is eluding me, much to my frustration. I'd appreciate some help</p>
  
  <p>Thanks</p>
  
  <p>@MarcB
  file from excel: (cut'n'pasted from gedit; contrary to appearance there are no blank lines in this file; rather lines alternate int, str, int, str ...)
  0</p>
  
  <p>A?GATCGGAAGAGCGTCGTGTAGGGAAAGAGTGTAGATC
  1</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACATCACGAT[AC]T</p>
  
  <p>2</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACCGATGTAT[AC]T</p>
  
  <p>3</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTTAGGCAT[AC]T</p>
  
  <p>4</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTGACCAAT[AC]T</p>
  
  <p>5</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACACAGTGAT[AC]T</p>
  
  <p>6</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACGCCAATAT[AC]T</p>
  
  <p>7</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACCAGATCAT[AC]T</p>
  
  <p>8</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACACTTGAAT[AC]T</p>
  
  <p>9</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACGATCAGAT[AC]T</p>
  
  <p>10</p>
  
  <p>A?GATCGGAAGAGCACACGTCTGAACTCCAGTCACTAGCTTAT[AC]T</p>
  
  <pre><code>rtstxt='readthrusequences.txt'
  
  # establish readthrusequence array ---------------------------------------------
  # push into sparse array the readthru adapter sequence for each TruSeq index
  # use the TruSeq Index number as key to the sequence
  forts=${pathsir}${rtstxt}  # FileOf ReadThruSequences
    rts=( $(cat ${forts}) )
  
  idx=""
  elem=""
  isIdx=1
  for elem in ${rts[@]}; do
    echo '$elem:'${elem}
  # echo 'elem:' ${elem} 'before IF - isIdx:' $isIdx '- idx:' $idx
    if [[ $isIdx = 1 ]]; then 
      echo ' 1_block - $isIdx:'$isIdx' - elem:'$elem' - idx:'$idx; 
      indexseq[$elem]=0; 
      #echo "  indexseq[elem] set to ${indexseq[$elem]}"; 
      idx=$elem; 
      #echo "  idx set to elem (i.e. $idx)"; 
      isIdx=0; 
      #echo "  isIdx reset to $isIdx"; 
      #echo " " ; 
    else 
      #echo " 2_block - isIdx:$isIdx - elem:$elem - idx:$idx"; 
      indexseq[$idx]=$elem; 
      #echo "  indexseq[idx] set to ${indexseq[$idx]}"; 
      isIdx="1"; idx="0"; 
      #echo "  isIdx reset to $isIdx - idx reset to $idx";
      #echo ""; 
    fi
  #  echo "keys (TruSeq index): ${!indexseq[*]}"
  #  echo "vals (indexed adapter seq): ${indexseq[*]}"
  done
  </code></pre>
  
  <p>This code pushes the file contents into an array, using the int as indices and the str and values. </p>
  
  <p>The commented lines were debugs. If the first is un-commented the console yields</p>
  
  <pre><code>before IF - isIdx: 1 - idx:
   - idx:k - $isIdx:1 - elem:0
  ")syntax error: invalid arithmetic operator (error token is "
  </code></pre>
  
  <p>pointing definitely to a line end issue; but I've banged my head on this wall for too long &amp; haven't found a solution. I know there's a simple one ... </p>