Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is sort -k not working all the time?
    primarykey
    data
    text
    <p>I have now a script that puts a list of files in two separate arrays:</p> <p>First, I get a file list from a ZIP file and fill <code>FIRST_Array()</code> with it. Second, I get a file list from a control file within a ZIP file and fill <code>SECOND_Array()</code> with it</p> <pre><code>while read length date time filename do FIRST_Array+=( "$filename" ) echo "$filename" &gt;&gt; FIRST.report.out done &lt; &lt;(/usr/bin/unzip -qql AAA.ZIP |sort -g -k12 -t~) </code></pre> <p>Third, I compare both array like so:</p> <pre><code>diff -q &lt;(printf "%s\n" "${FIRST_Array[@]}") &lt;(printf "%s\n" "${SECOND_Array[@]}") |wc -l </code></pre> <p>I can tell that <code>Diff</code> fails because I output each array to files: <code>FIRST.report.out</code> and <code>SECOND.report.out</code> are simply not sorted properly. </p> <p>1) FIRST.report.out (what's inside the ZIP file)</p> <p><code>JGS-Memphis~AT1~Pre-Test~X-BanhT~JGMDTV387~6~P~1100~HR24-500~033072053326~20120808~240914.XML JGS-Memphis~PRE~DTV_PREP~X-GuinE~JGMDTV069~6~P~1100~H24-700~033081107519~20120808~240914.XML JGS-Memphis~PRE~DTV_PREP~X-MooreBe~JGM98745~40~P~1100~H21-200~029264526103~20120808~240914.XML JGS-Memphis~FUN~Pre-Test~X-RossA~jgmdtv168~2~P~1100~H21-200~029415655926~20120808~240914.XML</code></p> <p>2) SECOND.report.out (what's inside the ZIP's control file)</p> <p><code>JGS-Memphis~AT1~Pre-Test~X-BanhT~JGMDTV387~6~P~1100~HR24-500~033072053326~20120808~240914.XML JGS-Memphis~FUN~Pre-Test~X-RossA~jgmdtv168~2~P~1100~H21-200~029415655926~20120808~240914.XML JGS-Memphis~PRE~DTV_PREP~X-GuinE~JGMDTV069~6~P~1100~H24-700~033081107519~20120808~240914.XML JGS-Memphis~PRE~DTV_PREP~X-MooreBe~JGM98745~40~P~1100~H21-200~029264526103~20120808~240914.XML</code></p> <p>Using <code>sort -k12 -t~</code> made sense since <code>~</code> is the delimiter for the file's date field (12th position). But it is not working consistently. Added <code>-g</code> made no difference.</p> <p>The sort is worse when my script processes bigger ZIP files. Why is sort -k not working all the time? How can I sort both arrays?</p>
    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. 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