Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>you can't change the <em>cursor</em> line of a <code>while read</code></li> </ul> <p>I wrote this for you with a little <a href="/questions/tagged/hack" class="post-tag" title="show questions tagged 'hack'" rel="tag">hack</a> to prefix the array names with <code>seq N+1</code> :</p> <pre><code>#!/bin/bash file=file.txt while read line; do if [[ $line == S* ]]; then echo "$line" i=0 ((Seq++)) else declare seq${Seq}_2ndColumn[i]="$(echo $line | cut -d\ -f2)" declare seq${Seq}_3rdColumn[i]="$(echo $line | cut -d\ -f3)" ((i++)) fi done &lt; "$file" echo "${!seq*} arrays are declared" </code></pre> <p><strong>OUTPUT</strong></p> <pre><code>seq1_2ndColumn seq1_3rdColumn seq2_2ndColumn seq2_3rdColumn arrays are declared </code></pre> <p><strong>EXPLANATIONS</strong></p> <ul> <li><code>${!pattern*}</code> is a nice feature of bash to display variables beginning with <em>pattern</em></li> <li><code>(( ))</code> is an arithmetic command, which returns an exit status of 0 if the expression is nonzero, or 1 if the expression is zero. Also used as a synonym for "let", if side effects (assignments) are needed. See <a href="http://mywiki.wooledge.org/ArithmeticExpression" rel="nofollow">http://mywiki.wooledge.org/ArithmeticExpression</a></li> </ul> <p><strong>BONUS</strong></p> <p>If you have the control on what's in your array, try doing this at the end ::</p> <pre><code>for s in ${!seq*}; do printf '\t%s\n' $(eval echo \${$s[@]}) done </code></pre> <p>See See <a href="http://mywiki.wooledge.org/BashFAQ/048" rel="nofollow">http://mywiki.wooledge.org/BashFAQ/048</a> </p> <p>new <strong>OUTPUT</strong></p> <pre><code>seq1_2ndColumn 1 2 3 seq1_3rdColumn 5 6 9 seq2_2ndColumn 2 4 8 seq2_3rdColumn 7 9 12 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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