<?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: Organize data in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088038#M93101</link>
    <description>Hi JRF...&lt;BR /&gt;&lt;BR /&gt;Ow... I really appreciate your answers, can you send a shell script program too? Because is going to make a part of another script that I'm writing...&lt;BR /&gt;&lt;BR /&gt;Your answer help me a lot, but if could help once...&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Andre&lt;BR /&gt;</description>
    <pubDate>Tue, 15 Jan 2008 15:04:59 GMT</pubDate>
    <dc:creator>Andre Augusto Ferreira</dc:creator>
    <dc:date>2008-01-15T15:04:59Z</dc:date>
    <item>
      <title>Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088035#M93098</link>
      <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;I have the follow entrie:&lt;BR /&gt;&lt;BR /&gt;a data1 data2 data3&lt;BR /&gt;a data4 data5 data6&lt;BR /&gt;a data7 data8 data9 data10&lt;BR /&gt;a data11 data12 data13&lt;BR /&gt;d data1 data2 data3&lt;BR /&gt;d data4 data5 data6 data7 data8&lt;BR /&gt;d data9 data10 data11&lt;BR /&gt;b data1 data2 data3&lt;BR /&gt;b data4 data5 data6&lt;BR /&gt;b data7 data8 data9&lt;BR /&gt;b data10 data11 data12 data13&lt;BR /&gt;b data14 data15 data16&lt;BR /&gt;&lt;BR /&gt;How can I reorganize it and get the follow structure:&lt;BR /&gt;&lt;BR /&gt;a&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9 data10&lt;BR /&gt;data11 data12 data13&lt;BR /&gt;======&lt;BR /&gt;b&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9&lt;BR /&gt;data10 data11 data12 data13&lt;BR /&gt;data14 data15 data16&lt;BR /&gt;======&lt;BR /&gt;d&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6 data7 data8&lt;BR /&gt;data9 data10 data11&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;&lt;BR /&gt;Andre</description>
      <pubDate>Tue, 15 Jan 2008 13:46:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088035#M93098</guid>
      <dc:creator>Andre Augusto Ferreira</dc:creator>
      <dc:date>2008-01-15T13:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088036#M93099</link>
      <description>&lt;!--!*#--&gt;Hi Andre:&lt;BR /&gt;&lt;BR /&gt;Given the data as shown, the first thing we need to do is filter it so it can be sorted.  To keep the order you want, we need to temporarily append a zero to each item with a single digit; sort the file; and then strip the added digit.  We could do this like:&lt;BR /&gt;&lt;BR /&gt;# perl -ple 's/(\D+)(\d)\s/${1}0${2} /' myfile | sort -k1,1 | perl -ple 's/0(\d\s)/$1/'&lt;BR /&gt;&lt;BR /&gt;Next, pipe the output of the above to this:&lt;BR /&gt;&lt;BR /&gt;# cat .filter&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ( $n, $tag, $oldtag ) = ( 0, undef, undef );&lt;BR /&gt;my @fields;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    @fields = split;&lt;BR /&gt;    $tag    = shift @fields;&lt;BR /&gt;    if ( $n == 0 ) {&lt;BR /&gt;        $n++;&lt;BR /&gt;        print "$tag\n";&lt;BR /&gt;        $oldtag = $tag;&lt;BR /&gt;    }&lt;BR /&gt;    if ( $tag ne $oldtag ) {&lt;BR /&gt;        print "======\n", $tag, "\n";&lt;BR /&gt;        $oldtag = $tag;&lt;BR /&gt;    }&lt;BR /&gt;    print "@fields\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Overall:&lt;BR /&gt;&lt;BR /&gt;# perl -ple 's/(\D+)(\d)\s/${1}0${2} /' ./myfile | sort -k1,1 | perl -ple 's/0(\d\s)/$1/' | ./filter&lt;BR /&gt;&lt;BR /&gt;a&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9 data10&lt;BR /&gt;data11 data12 data13&lt;BR /&gt;======&lt;BR /&gt;b&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9&lt;BR /&gt;data10 data11 data12 data13&lt;BR /&gt;data14 data15 data16&lt;BR /&gt;======&lt;BR /&gt;d&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6 data7 data8&lt;BR /&gt;data9 data10 data11&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 15 Jan 2008 14:39:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088036#M93099</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-15T14:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088037#M93100</link>
      <description>&lt;!--!*#--&gt;Hi (again) Andre:&lt;BR /&gt;&lt;BR /&gt;If the above post meets your needs, this is a simple integrated script:&lt;BR /&gt;&lt;BR /&gt;# cat ./filter&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ( $n, $tag, $oldtag ) = ( 0, undef, undef );&lt;BR /&gt;my ( @list, @fields );&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    s/(\D+)(\d)\s/${1}0${2} /;&lt;BR /&gt;    push @list, $_;&lt;BR /&gt;}&lt;BR /&gt;@list = sort @list;&lt;BR /&gt;for (@list) {&lt;BR /&gt;    s/0(\d\s)/$1/;&lt;BR /&gt;    @fields = split;&lt;BR /&gt;    $tag    = shift @fields;&lt;BR /&gt;    if ( $n == 0 ) {&lt;BR /&gt;        $n++;&lt;BR /&gt;        print "$tag\n";&lt;BR /&gt;        $oldtag = $tag;&lt;BR /&gt;    }&lt;BR /&gt;    if ( $tag ne $oldtag ) {&lt;BR /&gt;        print "======\n", $tag, "\n";&lt;BR /&gt;        $oldtag = $tag;&lt;BR /&gt;    }&lt;BR /&gt;    print "@fields\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then, simply run as:&lt;BR /&gt;&lt;BR /&gt;# ./filter file&lt;BR /&gt;a&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9 data10&lt;BR /&gt;data11 data12 data13&lt;BR /&gt;======&lt;BR /&gt;b&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9&lt;BR /&gt;data10 data11 data12 data13&lt;BR /&gt;data14 data15 data16&lt;BR /&gt;======&lt;BR /&gt;d&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6 data7 data8&lt;BR /&gt;data9 data10 data11&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 15 Jan 2008 14:53:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088037#M93100</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-15T14:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088038#M93101</link>
      <description>Hi JRF...&lt;BR /&gt;&lt;BR /&gt;Ow... I really appreciate your answers, can you send a shell script program too? Because is going to make a part of another script that I'm writing...&lt;BR /&gt;&lt;BR /&gt;Your answer help me a lot, but if could help once...&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Andre&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jan 2008 15:04:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088038#M93101</guid>
      <dc:creator>Andre Augusto Ferreira</dc:creator>
      <dc:date>2008-01-15T15:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088039#M93102</link>
      <description>Andre, just call the perl as a function from the outer shell??&lt;BR /&gt;If you can not accept a perl solution, then please indicate so. Also please re-consider as it it often rather efficient and just about as easy to maintain as a shell script, even for non-perl folks.&lt;BR /&gt;&lt;BR /&gt;In your example output is there a "=====" missing after the last block, or before the first block, or is this exactly as desired?&lt;BR /&gt;&lt;BR /&gt;Here is an other (perl, sorry) alternative:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#------------- group.pl --------&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my ($name, %tables);&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  m/^(.)\s(.*)/;&lt;BR /&gt;  push @{ $tables{$1} }, $2;&lt;BR /&gt;}&lt;BR /&gt;foreach $name (sort keys %tables) {&lt;BR /&gt;  print "$name\n";&lt;BR /&gt;  foreach (@{$tables{$name}}) {&lt;BR /&gt;    print "$_\n";&lt;BR /&gt;  }&lt;BR /&gt;  print "=======\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;This script uses an 'hash' with an array for each group. As data comes in, it is pushed (at the end) of the array in the hash identified by the first character.&lt;BR /&gt;[note: if you want that to be a word use: m/^(\S+)\s+(.*)/  ]&lt;BR /&gt;When all data is read, return the sorted key values for the array (those first chars). Next use that to grab the arrays themself and print.&lt;BR /&gt;&lt;BR /&gt;use as :&lt;BR /&gt;&lt;BR /&gt;./group.pl list.txt &amp;gt; group.txt&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;perl group.pl list.txt &amp;gt; group.txt&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jan 2008 17:13:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088039#M93102</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-01-15T17:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088040#M93103</link>
      <description>Hi Hein,&lt;BR /&gt;&lt;BR /&gt;Thank you very much for your alternative and explanation, I'm accepting any kind of yours smart sugestions. Like you said, I can use the perl solution, and both work very well.&lt;BR /&gt;&lt;BR /&gt;I'm newer in perl, and this scripts help me to learn many tips, logics, commands and is most efficient. I'd like to receive a shell sugestion because for 2 days I'm trying to write and studying, but I didn't get it... &lt;BR /&gt;&lt;BR /&gt;Any other solution will be welcome (perl, shell, etc).&lt;BR /&gt;&lt;BR /&gt;The output "=====" is just to separate the blocks, is not a requirement.&lt;BR /&gt;&lt;BR /&gt;Thank you again&lt;BR /&gt;&lt;BR /&gt;Andre</description>
      <pubDate>Tue, 15 Jan 2008 18:08:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088040#M93103</guid>
      <dc:creator>Andre Augusto Ferreira</dc:creator>
      <dc:date>2008-01-15T18:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088041#M93104</link>
      <description>&lt;!--!*#--&gt;If you are familiar with awk(1) then you can try the construct below. Simply copy and paste it inside your shell script:&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;  for(i=2;i&amp;lt;=NF;i++) l=l?l" "$i:$i&lt;BR /&gt;  x[$1]=x[$1]?x[$1]"\n"l:l&lt;BR /&gt;  l=""&lt;BR /&gt;} END {&lt;BR /&gt;  for(i in x) {&lt;BR /&gt;     if (i!=prev) print "======"&lt;BR /&gt;     print i"\n"x[i]&lt;BR /&gt;     prev=i&lt;BR /&gt;  }&lt;BR /&gt;}' file</description>
      <pubDate>Tue, 15 Jan 2008 20:09:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088041#M93104</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2008-01-15T20:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088042#M93105</link>
      <description>hi andre ;&lt;BR /&gt;&lt;BR /&gt;i did not test but this should works.&lt;BR /&gt;&lt;BR /&gt;cat file | cut -b 0-1 | sort | uniq  | while read VAR1&lt;BR /&gt;do&lt;BR /&gt;echo $VAR1&lt;BR /&gt;grep "^${VAR1} file | cut -b 1-120 &lt;BR /&gt;echo "======="&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hasan.</description>
      <pubDate>Tue, 15 Jan 2008 20:24:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088042#M93105</guid>
      <dc:creator>Hasan  Atasoy</dc:creator>
      <dc:date>2008-01-15T20:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088043#M93106</link>
      <description>Hello guys,&lt;BR /&gt;&lt;BR /&gt;Very good help... &lt;BR /&gt;&lt;BR /&gt;Hasan, I've just changed the value of "cut -b 1-120" to "cut -b 3-120" and works fine.&lt;BR /&gt;&lt;BR /&gt;Sandman, the output of your routine begin with the last block sequence (with the letter "d"):&lt;BR /&gt;======&lt;BR /&gt;d&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6 data7 data8&lt;BR /&gt;data9 data10 data11&lt;BR /&gt;======&lt;BR /&gt;a&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9 data10&lt;BR /&gt;data11 data12 data13&lt;BR /&gt;======&lt;BR /&gt;b&lt;BR /&gt;data1 data2 data3&lt;BR /&gt;data4 data5 data6&lt;BR /&gt;data7 data8 data9&lt;BR /&gt;data10 data11 data12 data13&lt;BR /&gt;data14 data15 data16&lt;BR /&gt;&lt;BR /&gt;Can we change it, and put it in alphabetical order?&lt;BR /&gt;&lt;BR /&gt;Thanks all</description>
      <pubDate>Tue, 15 Jan 2008 21:16:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088043#M93106</guid>
      <dc:creator>Andre Augusto Ferreira</dc:creator>
      <dc:date>2008-01-15T21:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088044#M93107</link>
      <description>Sandman, &lt;BR /&gt;   Correct me if I'm wrong, but your solution seems to rely on order in the way elements are returned from an awk array.&lt;BR /&gt;This can not be relied upon. My documentation explicitly states: "The order in which elements of teh array are accessed (by this statement) is determined by the internal arrangement of the array elements within awk and cannot be controlled or changed". Change the leading a in the 2nd or 3rd line to 'x' and try again.&lt;BR /&gt;&lt;BR /&gt;Hasan,&lt;BR /&gt;&lt;BR /&gt;Not bad. Bot bad. But why not try?&lt;BR /&gt;&lt;BR /&gt;To make this work change to:&lt;BR /&gt;&lt;BR /&gt;grep "^${VAR1}" file | cut -b 3-120&lt;BR /&gt;&lt;BR /&gt;And optionally:&lt;BR /&gt;&lt;BR /&gt;$ cut -b 0-1 file | sort -u | while read VAR1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jan 2008 21:19:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088044#M93107</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-01-15T21:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088045#M93108</link>
      <description>&lt;!--!*#--&gt;You can try the following.  If you don't care about stable sorts, you don't need that nl(1):&lt;BR /&gt;# number lines if stable sort needed&lt;BR /&gt;nl -ba -nrz file | sort -k2,2 -k1n,1n | awk '&lt;BR /&gt;BEGIN { LAST="" }&lt;BR /&gt;{&lt;BR /&gt;if ($2 != LAST) {  # list header&lt;BR /&gt;   if (LAST != "") print "===="&lt;BR /&gt;   print $2&lt;BR /&gt;   LAST = $2&lt;BR /&gt;}&lt;BR /&gt;# print rest of line&lt;BR /&gt;for (i = 3; i &amp;lt; NF; ++i) printf $i " "&lt;BR /&gt;print $NF&lt;BR /&gt;}&lt;BR /&gt;END { print "====" } '</description>
      <pubDate>Wed, 16 Jan 2008 03:44:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088045#M93108</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-01-16T03:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088046#M93109</link>
      <description>&lt;!--!*#--&gt;Hi Andre,&lt;BR /&gt;this run fine on my HPUX11i:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;sort your_file -o temp_file&lt;BR /&gt;for key in $(cut -d " " -f1 temp_file|uniq)&lt;BR /&gt;do&lt;BR /&gt;        echo $key&lt;BR /&gt;        grep "^$key " temp_file| cut -c 3-&lt;BR /&gt;        echo "="&lt;BR /&gt;done&lt;BR /&gt;rm temp_file&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Wed, 16 Jan 2008 09:58:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088046#M93109</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2008-01-16T09:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088047#M93110</link>
      <description>Hi again guys,&lt;BR /&gt;&lt;BR /&gt;I wanna thank you for the replies, now I have a lot of ideas to my script, all these answers works very very well.&lt;BR /&gt;&lt;BR /&gt;Finally, thanks to Dennis and Arturo for the simple scripts.&lt;BR /&gt;&lt;BR /&gt;You are great... This foruns help much more than a lot of books.&lt;BR /&gt;&lt;BR /&gt;AndrÃ©</description>
      <pubDate>Wed, 16 Jan 2008 12:51:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088047#M93110</guid>
      <dc:creator>Andre Augusto Ferreira</dc:creator>
      <dc:date>2008-01-16T12:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Organize data</title>
      <link>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088048#M93111</link>
      <description>Close</description>
      <pubDate>Wed, 16 Jan 2008 12:52:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/organize-data/m-p/5088048#M93111</guid>
      <dc:creator>Andre Augusto Ferreira</dc:creator>
      <dc:date>2008-01-16T12:52:08Z</dc:date>
    </item>
  </channel>
</rss>

