or maybe in bash.. script/"one liner" e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ
i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A
So from the input, i want to make an ascendant order, how many things are under a "SOMETHING-XX"
Does anyone has any "perl magic" in the pocket, how to do this? :D
Thank you very, very much..:\
The solution [from the FreeBSD mailing list]:
perl -00 -e 'print map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, tr/\n//], <>' < before.txt > after.txt
Thank you!!
or maybe in bash.. script/"one liner" e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ
i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A
So from the input, i want to make an ascendant order, how many things are under a "SOMETHING-XX"
Does anyone has any "perl magic" in the pocket, how to do this? :D
Thank you very, very much..:\
On Sun, May 23, 2010 at 5:39 PM, Jozsi Vadkan jozsi.avadkan@gmail.com wrote:
The solution [from the FreeBSD mailing list]:
perl -00 -e 'print map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, tr/\n//], <>' < before.txt > after.txt
Wow...
On 05/24/2010 06:39 AM, Jozsi Vadkan wrote:
The solution [from the FreeBSD mailing list]:
perl -00 -e 'print map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, tr/\n//], <>' < before.txt > after.txt
Thank you!!
FYI a lovely piece of magic from 1994:-)
http://en.wikipedia.org/wiki/Schwartzian_transform
Kal
On Sun, May 23, 2010 at 1:15 PM, Jozsi Vadkan jozsi.avadkan@gmail.com wrote:
or maybe in bash.. script/"one liner" e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ
i want to make this output from it: http://pastebin.com/raw.php?i=kH8VxT0A
So from the input, i want to make an ascendant order, how many things are under a "SOMETHING-XX"
Does anyone has any "perl magic" in the pocket, how to do this? :D
Ok, I'l bite, hope John D. isn't looking...
This is as close as I can get. I shall confess I'm cheating; I had to add two extra blank lines at the beginning of your file. Don't know if allowed. Also, SOMETHING-blocks look collapsed; don't know if bug or feature for you :D Anyway, it can make for a start.
perl -ne '$/="\n\n"; @a=split(); push @b,({q=>scalar(@a),l=>[@a]});END{for $i (sort {$a->{q} <=> $b->{q}} @b) {print "@{$i->{l}}\n"}}' < raw.txt
SOMETHING-85-uj sfvtc SOMETHING-86 yxcver SOMETHING-88 yxfrf yxwwcc SOMETHING-82-H sdfyxcv asdfyxcv asdfgyx SOMETHING-82 lajsldfj alsdfjlas djfalsd asdfasd dsfx SOMETHING-85 xdfvqe asdwe yxccv cxvbe wdyfv qyxvvy yxcvtg yxcvgt
For the sake of really helping, let's analyze a bit:
$/= we are replacing record separator for split() @a = split() split in list context, give me the actual lines $a = scalar(@a) give me the number of lines @b is a list to throw our (#lines, lines) pairs into {q=>$a,l=>[@a]} is a hash with two keys, q (#lines) and l (lines) END{} when all else is done sort {$a->{q} <=> $b->{q}} @b give me b sorted by q print "@{$i->{l}}\n" print each l element as a list
HTH