<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: sorting files in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176801#M91283</link>
    <description>Hi,&lt;BR /&gt;i missed to write something.in the "test" file&lt;BR /&gt;&lt;BR /&gt;vi test&lt;BR /&gt;----------&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat</description>
    <pubDate>Wed, 09 Apr 2008 10:36:43 GMT</pubDate>
    <dc:creator>Aashique</dc:creator>
    <dc:date>2008-04-09T10:36:43Z</dc:date>
    <item>
      <title>sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176798#M91280</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I want to sort below files in a particular order&lt;BR /&gt;&lt;BR /&gt;currently it is like below:&lt;BR /&gt;&amp;gt;ls&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;i want to sort it like this&lt;BR /&gt;&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;&lt;BR /&gt;i.e i want the standard files for a country first ( fancy_STD_HK...) and then its corresponding language files(fancy_STD_LANG_HK_...).&lt;BR /&gt;&lt;BR /&gt;Please let me know how it can be done&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan</description>
      <pubDate>Wed, 09 Apr 2008 10:07:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176798#M91280</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-04-09T10:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176799#M91281</link>
      <description>&lt;!--!*#--&gt;You'll need to break up the filenames using awk then use sort:&lt;BR /&gt;ls | awk -F_ '&lt;BR /&gt;{&lt;BR /&gt;if ($2 == "LANG") {&lt;BR /&gt;  # combine fields&lt;BR /&gt;  country = $4&lt;BR /&gt;  lang = "STDLANG"&lt;BR /&gt;} else {&lt;BR /&gt;  country = $3&lt;BR /&gt;  lang = $2&lt;BR /&gt;}&lt;BR /&gt;print country, lang, $1, $0&lt;BR /&gt;}' | sort | awk '{print $4}'&lt;BR /&gt;&lt;BR /&gt;Did you want to also sort by the first "fancy" or the date?</description>
      <pubDate>Wed, 09 Apr 2008 10:29:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176799#M91281</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-04-09T10:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176800#M91282</link>
      <description>Hi,&lt;BR /&gt;first create a file with all your country code&lt;BR /&gt;lets say test1&lt;BR /&gt;&lt;BR /&gt;vi test1&lt;BR /&gt;-----------&lt;BR /&gt;AU&lt;BR /&gt;HK&lt;BR /&gt;NZ&lt;BR /&gt;&lt;BR /&gt;then write another sctipt name "test2"&lt;BR /&gt;&lt;BR /&gt;vi test2&lt;BR /&gt;--------&lt;BR /&gt;set `cat test1`&lt;BR /&gt;for i in $*&lt;BR /&gt;do&lt;BR /&gt;grep $i test|sort -rn&amp;gt;&amp;gt;test3&lt;BR /&gt;&lt;BR /&gt;$ more test3&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks &amp;amp; Regards&lt;BR /&gt;&lt;BR /&gt;Aashique</description>
      <pubDate>Wed, 09 Apr 2008 10:34:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176800#M91282</guid>
      <dc:creator>Aashique</dc:creator>
      <dc:date>2008-04-09T10:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176801#M91283</link>
      <description>Hi,&lt;BR /&gt;i missed to write something.in the "test" file&lt;BR /&gt;&lt;BR /&gt;vi test&lt;BR /&gt;----------&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat</description>
      <pubDate>Wed, 09 Apr 2008 10:36:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176801#M91283</guid>
      <dc:creator>Aashique</dc:creator>
      <dc:date>2008-04-09T10:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176802#M91284</link>
      <description>At first is seems you can just sort specifying -t_ to make underscore be a field terminator. But the field number also changes.&lt;BR /&gt;&lt;BR /&gt;So you need a sort with a twist.&lt;BR /&gt;Here is a perl solution:&lt;BR /&gt;&lt;BR /&gt;$ cat x&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;&lt;BR /&gt;$ perl -e  'sub twist {$x=@_[0]; $x=~s/_LANG(_STD_..)_/${1}x/; return $x}; print sort {twist($a) cmp twist($b)} &amp;lt;&amp;gt;' x&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;&lt;BR /&gt;Just to clarify, here is that twist function alone at work:&lt;BR /&gt;&lt;BR /&gt;$ perl -e  'sub twist {$x=@_[0]; $x=~s/_LANG(_STD_..)_/${1}x/; return $x}; foreach (&amp;lt;&amp;gt;) {print twist($_)}' x&lt;BR /&gt;fancy_STD_AUx2008-03-05.dat&lt;BR /&gt;fancy_STD_HKx2008-03-06.dat&lt;BR /&gt;fancy_STD_NZx2008-03-05.dat&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Apr 2008 11:16:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176802#M91284</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-04-09T11:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176803#M91285</link>
      <description>Hi again,&lt;BR /&gt;I am not so familiar with perl.&lt;BR /&gt;I am trying something like this&lt;BR /&gt;local filelist="$@"&lt;BR /&gt;where filelist contains all the list of files passed from someother file.&lt;BR /&gt;&lt;BR /&gt;Now how do i sort it,i tried Dennis' solution&lt;BR /&gt;local filelist="$@"&lt;BR /&gt;local filesortedlist=`echo $filelist | awk -F_ '&lt;BR /&gt;{&lt;BR /&gt;if ($2 == "LANG") {&lt;BR /&gt;  # combine fields&lt;BR /&gt;  country = $4&lt;BR /&gt;  lang = "STDLANG"&lt;BR /&gt;} else {&lt;BR /&gt;  country = $3&lt;BR /&gt;  lang = $2&lt;BR /&gt;}&lt;BR /&gt;print country, lang, $1, $0&lt;BR /&gt;}' | sort | awk '{print $4}'`;&lt;BR /&gt;&lt;BR /&gt;but filesortedlist contains only the first of the sorted file(i.e fancy_STD_AU_2008-03-05.dat).&lt;BR /&gt;I want all the sorted files into a variable(filesortedlist).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan</description>
      <pubDate>Wed, 09 Apr 2008 13:09:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176803#M91285</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-04-09T13:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176804#M91286</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;If you want to use Dennis' solution, you began with:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; local filelist="$@"&lt;BR /&gt;&amp;gt; local filesortedlist=`echo $filelist | awk -F_ '&lt;BR /&gt;&lt;BR /&gt;This would work if you changed the 'echo' to 'cat' in order to read the file represented by 'filelist'.  You don't need to create a separate process with 'cat' to pipe the output to 'awk'.  That is wasteful!&lt;BR /&gt;&lt;BR /&gt;Using Dennis's solution and your surrounding shell logic (as written):&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;local filelist="$@"&lt;BR /&gt;local filesortedlist=`awk -F_ '&lt;BR /&gt;{&lt;BR /&gt;if ($2 == "LANG") {&lt;BR /&gt;# combine fields&lt;BR /&gt;country = $4&lt;BR /&gt;lang = "STDLANG"&lt;BR /&gt;} else {&lt;BR /&gt;country = $3&lt;BR /&gt;lang = $2&lt;BR /&gt;}&lt;BR /&gt;print country, lang, $1, $0&lt;BR /&gt;}' $filelist | sort | awk '{print $4}'` ;&lt;BR /&gt;echo ${filesortedlist}&lt;BR /&gt;&lt;BR /&gt;...That is, 'awk' takes the first argument supplied to it as a FILE to be opened and read.  The output of the 'awk' process is then piped to a 'sort'.&lt;BR /&gt;&lt;BR /&gt;Perl makes this process-efficient.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 09 Apr 2008 13:42:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176804#M91286</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-04-09T13:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176805#M91287</link>
      <description>well, this seams a perfect excuse te learn perl to me!&lt;BR /&gt;&lt;BR /&gt;If you do, be sure to think outside the immediate question and ask yourself how the input came to be, and what is going to be done with the output.&lt;BR /&gt;You may well find that those steps are in fact better done in perl as well.&lt;BR /&gt;&lt;BR /&gt;Anyway... the awk solution failed because all data line were really words in a string.&lt;BR /&gt;So you'd have to split those first.&lt;BR /&gt;&lt;BR /&gt;This calls for a minor variation on Dennis's suggestion:&lt;BR /&gt;&lt;BR /&gt;Too bad hpux does not have an asorti function like 'gawk'&lt;BR /&gt;&lt;BR /&gt;$ cat x&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;$ local filelist=$(cat x)&lt;BR /&gt;$ echo $filelist&lt;BR /&gt;...&lt;BR /&gt;$ echo $filelist | awk '{while (++i&lt;NF&gt;&lt;/NF&gt;fancy_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_AU_2008-03-05.dat&lt;BR /&gt;fancy_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_LANG_STD_HK_2008-03-06.dat&lt;BR /&gt;fancy_STD_NZ_2008-03-05.dat&lt;BR /&gt;fancy_LANG_STD_NZ_2008-03-05.dat&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;core: &lt;BR /&gt;while (++i&lt;NF&gt;&lt;/NF&gt;split($i,x,"_")     # each field is split into array x by "_"&lt;BR /&gt;y=(x[2]=="LANG")?4:3 # is sub-field 2 = LANG?&lt;BR /&gt;                     # then language is in 4, not 3.&lt;BR /&gt;print x[y],y,$i}     # print language,helper,file ready for sorting&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Apr 2008 14:06:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176805#M91287</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-04-09T14:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176806#M91288</link>
      <description>Thanks everybody.I guess its time for me to start cramping perl&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan</description>
      <pubDate>Thu, 10 Apr 2008 05:57:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176806#M91288</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-04-10T05:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176807#M91289</link>
      <description>Hi everybody,&lt;BR /&gt;&lt;BR /&gt;Just when things were going fine,i got a big hiccup, the filelist has more than 100 files and when i use the below code&lt;BR /&gt;&lt;BR /&gt; local flist="$@"&lt;BR /&gt;        local filelist=`echo $flist | awk '{&lt;BR /&gt;        while (++i&amp;lt;=NF) {&lt;BR /&gt;        split($i,x,"_");&lt;BR /&gt;        y=(x[2]=="LANG")?4:3;&lt;BR /&gt;        print x[y],y,$i}&lt;BR /&gt;                       }' | sort -t"-" +1 +2 | awk '{print $3}'`;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I am getting an error like&lt;BR /&gt;&lt;BR /&gt;: Input line FANCY_LANG_STD_AU_20 cannot be longer than 3,000 bytes.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I tried something like&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;local filelist=`echo $flist | fold -w | awk '{.... but the last the sorting of the files  fails :(&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan</description>
      <pubDate>Thu, 01 May 2008 16:32:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176807#M91289</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-05-01T16:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176808#M91290</link>
      <description>Hi Gyan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Just when things were going fine,i got a big hiccup, the filelist has more than 100 files&lt;BR /&gt;&lt;BR /&gt;This is yet another reason to use Perl.  I suggest you use Hein's Perl solution.  You can specific mulitple files as the argument:&lt;BR /&gt;&lt;BR /&gt;# perl -e ' ... ' file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;OR you could do:&lt;BR /&gt;&lt;BR /&gt;# perl -e ' ... ' $(cat /home/filelist)&lt;BR /&gt;&lt;BR /&gt;...where '/home/filelist' contains the list of filenames (one per line) that you want to process.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 01 May 2008 16:51:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176808#M91290</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-01T16:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176809#M91291</link>
      <description>&lt;BR /&gt;Hi JRF,&lt;BR /&gt;&lt;BR /&gt;I agree with you but the problem is the scripts were already written using bash.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Gyan</description>
      <pubDate>Thu, 01 May 2008 17:05:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176809#M91291</guid>
      <dc:creator>Gyankr</dc:creator>
      <dc:date>2008-05-01T17:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176810#M91292</link>
      <description>Hi (again) Gyan:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I agree with you but the problem is the scripts were already written using bash.&lt;BR /&gt;&lt;BR /&gt;Well, 'awk' has limits that Perl doesn't.  If by 'bash' you mean a shell script that invokes 'awk', then I'd ask you why a shell script that invokes a Perl script is any different.  After all, isn't the objective to get the job done?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 01 May 2008 17:11:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176810#M91292</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-01T17:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: sorting files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176811#M91293</link>
      <description>&lt;!--!*#--&gt;&amp;gt;i got a big hiccup, the filelist has more than 100 files and when i use the below code&lt;BR /&gt;&amp;gt;I am getting an error like&lt;BR /&gt;Input line FANCY_LANG_STD_AU_20 cannot be longer than 3,000 bytes.&lt;BR /&gt;&lt;BR /&gt;My original file based script works fine since it only has one file per line.&lt;BR /&gt;&lt;BR /&gt;So you need to change your flist and write each filename to a file:&lt;BR /&gt;for i in $flist; do&lt;BR /&gt;   echo $i&lt;BR /&gt;done &amp;gt; file&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 01 May 2008 20:17:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sorting-files/m-p/4176811#M91293</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-01T20:17:32Z</dc:date>
    </item>
  </channel>
</rss>

