<?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>question Re: how to sort the file name in shell script in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191096#M80677</link>
    <description>&lt;A rel="user" href="https://community.cloudera.com/users/1842/lsundar19.html" nodeid="1842"&gt;@Sundar Lakshmanan&lt;/A&gt;&lt;P&gt;You can simply use "sort" command.&lt;/P&gt;&lt;PRE&gt;[root@node1 ~]# cat /tmp/a.txt
abcd_2_20180703
abcd_4_20180703
abcd_5_20180703
abcd_1_20180703
abcd_3_20180703
abcd_6_20180703


[root@node1 ~]# sort /tmp/a.txt
abcd_1_20180703
abcd_2_20180703
abcd_3_20180703
abcd_4_20180703
abcd_5_20180703
abcd_6_20180703
&lt;/PRE&gt;&lt;P&gt;Let me know if this helps.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jul 2018 17:01:04 GMT</pubDate>
    <dc:creator>sandyy006</dc:creator>
    <dc:date>2018-07-13T17:01:04Z</dc:date>
    <item>
      <title>how to sort the file name in shell script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191095#M80676</link>
      <description>&lt;P&gt;How to sort the filename in shell.&lt;/P&gt;&lt;P&gt;My files looks like &lt;/P&gt;&lt;P&gt;abcd_2_20180703&lt;/P&gt;&lt;P&gt;abcd_4_20180703&lt;/P&gt;&lt;P&gt;abcd_5_20180703&lt;/P&gt;&lt;P&gt;abcd_1_20180703&lt;/P&gt;&lt;P&gt;abcd_3_20180703&lt;/P&gt;&lt;P&gt;abcd_6_20180703&lt;/P&gt;&lt;P&gt;And i expect after the sorting &lt;/P&gt;&lt;P&gt;abcd_1_20180703&lt;/P&gt;&lt;P&gt;abcd_2_20180703&lt;/P&gt;&lt;P&gt;abcd_3_20180703&lt;/P&gt;&lt;P&gt;abcd_5_20180703&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;Please help me sort the files. TIA&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 15:06:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191095#M80676</guid>
      <dc:creator>lsundar19</dc:creator>
      <dc:date>2018-07-13T15:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to sort the file name in shell script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191096#M80677</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/1842/lsundar19.html" nodeid="1842"&gt;@Sundar Lakshmanan&lt;/A&gt;&lt;P&gt;You can simply use "sort" command.&lt;/P&gt;&lt;PRE&gt;[root@node1 ~]# cat /tmp/a.txt
abcd_2_20180703
abcd_4_20180703
abcd_5_20180703
abcd_1_20180703
abcd_3_20180703
abcd_6_20180703


[root@node1 ~]# sort /tmp/a.txt
abcd_1_20180703
abcd_2_20180703
abcd_3_20180703
abcd_4_20180703
abcd_5_20180703
abcd_6_20180703
&lt;/PRE&gt;&lt;P&gt;Let me know if this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 17:01:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191096#M80677</guid>
      <dc:creator>sandyy006</dc:creator>
      <dc:date>2018-07-13T17:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to sort the file name in shell script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191097#M80678</link>
      <description>&lt;P&gt;@&lt;A href="https://community.hortonworks.com/users/10159/snemuri.html"&gt;Sandeep Nemuri&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply. the above sort will give correct output if the directory have only one day files. &lt;/P&gt;&lt;P&gt;if the directory have 20180704 files. &lt;/P&gt;&lt;P&gt;it sorted output like&lt;/P&gt;&lt;P&gt;abcd_1_20180703&lt;/P&gt;&lt;P&gt;abcd_1_20180704&lt;/P&gt;&lt;P&gt;abcd_2_20180703&lt;/P&gt;&lt;P&gt;abcd_2_20180704&lt;/P&gt;&lt;P&gt;abcd_3_20180703&lt;/P&gt;&lt;P&gt;abcd_3_20180704&lt;/P&gt;&lt;P&gt;abcd_4_20180703&lt;/P&gt;&lt;P&gt;abcd_4_20180704&lt;/P&gt;&lt;P&gt;abcd_5_20180703&lt;/P&gt;&lt;P&gt;abcd_5_20180704&lt;/P&gt;&lt;P&gt;abcd_6_20180703&lt;/P&gt;&lt;P&gt;abcd_6_20180704&lt;/P&gt;&lt;P&gt;But i expect&lt;/P&gt;&lt;P&gt;abcd_1_20180703&lt;/P&gt;&lt;P&gt;abcd_2_20180703&lt;/P&gt;&lt;P&gt;abcd_3_20180703&lt;/P&gt;&lt;P&gt;abcd_4_20180703&lt;/P&gt;&lt;P&gt;abcd_5_20180703&lt;/P&gt;&lt;P&gt;abcd_6_20180703&lt;/P&gt;&lt;P&gt;abcd_1_20180704&lt;/P&gt;&lt;P&gt;abcd_2_20180704&lt;/P&gt;&lt;P&gt;abcd_3_20180704&lt;/P&gt;&lt;P&gt;abcd_4_20180704&lt;/P&gt;&lt;P&gt;abcd_5_20180704&lt;/P&gt;&lt;P&gt;abcd_6_20180704&lt;/P&gt;&lt;P&gt;Any idea?&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 14:01:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191097#M80678</guid>
      <dc:creator>lsundar19</dc:creator>
      <dc:date>2018-07-15T14:01:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to sort the file name in shell script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191098#M80679</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/1842/lsundar19.html" nodeid="1842"&gt;@Sundar Lakshmanan&lt;/A&gt;
&lt;/P&gt;&lt;P&gt;Try sort with delimiter&lt;/P&gt;&lt;PRE&gt;# ls -1 | sort -t '_' -nk3

# ls -1 | sort -t '_' -nk3
abcd_1_20180703
abcd_2_20180703
abcd_3_20180703
abcd_4_20180703
abcd_5_20180703
abcd_6_20180703
abcd_1_20180704
abcd_2_20180704
abcd_3_20180704
abcd_4_20180704
abcd_5_20180704
abcd_6_20180704

#cat test.out  | sort -t '_' -nk3

&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Jul 2018 14:53:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191098#M80679</guid>
      <dc:creator>rguruvannagari</dc:creator>
      <dc:date>2018-07-15T14:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to sort the file name in shell script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191099#M80680</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/1842/lsundar19.html" nodeid="1842"&gt;@Sundar Lakshmanan&lt;/A&gt; "sort" was for the requirement this is mentioned in the question details. You can use the command which &lt;A rel="user" href="https://community.cloudera.com/users/3576/rguruvannagari.html" nodeid="3576"&gt;@rguruvannagari&lt;/A&gt; has mentioned in the above comment to sort with the date (3rd column). &lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 16:34:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191099#M80680</guid>
      <dc:creator>sandyy006</dc:creator>
      <dc:date>2018-07-15T16:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to sort the file name in shell script</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191100#M80681</link>
      <description>&lt;P&gt;Thanks @ &lt;A href="https://community.hortonworks.com/users/10159/snemuri.html"&gt;Sandeep Nemuri  &lt;/A&gt; @ &lt;A href="https://community.hortonworks.com/users/3576/rguruvannagari.html"&gt;rguruvannagari&lt;/A&gt; works fine &lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jul 2018 20:56:20 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/how-to-sort-the-file-name-in-shell-script/m-p/191100#M80681</guid>
      <dc:creator>lsundar19</dc:creator>
      <dc:date>2018-07-15T20:56:20Z</dc:date>
    </item>
  </channel>
</rss>

