QDB Quotes from #n42 @ IRCnet

Showing a quote...

Added by Gathond : < gathond at gathond dot dk >29/07/2008[-]225[+]#564
jul 29 17:43:06 <jak2000> mmm easy question how sort the files with ls command: ls and sorting of the SIZE column?
jul 29 17:44:38 --> leaw (~leaw@leaw.users.undernet.org) has joined #linux
jul 29 17:45:56 --- ufhpc_ is now known as ufhpc
jul 29 17:46:07 <-- leaw (~leaw@leaw.users.undernet.org) has left #linux
jul 29 17:47:25 <Gathond> jak2000: if it is so easy why do you need us to think up the answer?
jul 29 17:48:29 <Gathond> hint: it is easy, and man ls tells how
jul 29 17:48:40 <ufhpc> jak2000: You might want to take a look at the manpage for ls
jul 29 17:49:03 --> Fat-Frumos (~Frederico@189.43.241.2) has joined #linux
jul 29 17:49:09 <Gathond> ufhpc: or he could use a combination of ls, sort, awk and perl
jul 29 17:49:13 <jak2000> yes
jul 29 17:49:20 <Gathond> well and lets throw in some python as well just for kicks
jul 29 17:49:30 <Gathond> perhaps do it in lolcode
jul 29 17:49:37 <jak2000> bad typed: ls --sort -S but now work thanks: ls -S :)
jul 29 17:49:59 <ufhpc> Gathond: True. Althought ls -l | sort -k 5 works just fine
jul 29 17:50:22 <Gathond> http://www.dansdata.com/gz084.htm
jul 29 17:50:50 <ufhpc> Gathond: Granted, if you want to reverse the order, it puts the header at the foot of the list, but suck it up. :)
jul 29 17:50:54 <Gathond> I'm pretty sure that is not true, I'm pretty sure the strength meter in most laptops/cellphones IS the SNR and not the signal strength
jul 29 17:52:05 --- Fat-Frumos is now known as SirAngels
jul 29 17:52:08 <Gathond> or perhaps that is only the linux ones
jul 29 17:52:09 <Gathond> shrug
jul 29 17:52:44 <Gathond> ufhpc: works yes, but it is too simple, you will never be taken seriously if your solution is less than one screen:)
jul 29 17:55:13 <ufhpc> Gathond: Well... I suppose you could do it in perl by grabbing each line of the ls output, splitting it into words and lines on an array, then sorting the array, then iterating through the array again and printing out the proper result.
jul 29 17:55:24 * SirAngels is away (voi mai reveni)
jul 29 17:55:29 <Gathond> ufhpc: now you are talking:)
jul 29 17:56:45 <-- UncleTom has quit (Quit: Ex-Chat)
jul 29 17:56:54 <ufhpc> Of course, the real way to do that would be to use perl to grab it by lines, yank out the sizes in an indexed array, shove that indexed array into a temp file which then gets sorted using sort. You then pull the array back out, read in the new order of the indexes, and print out the lines according to that list.
jul 29 17:57:09 <Gathond> hehe
jul 29 17:57:13 --> unabonger (~barry@ip72-195-188-176.mc.at.cox.net) has joined #linux
jul 29 17:57:36 <ufhpc> Of course, you would want to encrypt all of the data that is not associated with the actual file sizes, for which I think I would use rot13.
jul 29 17:58:24 --> evilelf (~fuzzball@fuzzyelf.users.undernet.org) has joined #linux

jul 29 17:59:21 <ufhpc> Oooh! Wait! I know! Use perl to create a temporary table in a MySQL database, populate that database with the information from the ls output, then simply do a mysql query against the table with an order function in it. Should probably send commands to index the table by the filesize field as well to speed up the transaction

<stuff removed here />

jul 29 22:57:37 <ufhpc> Gathond: You around?
jul 29 23:04:18 <evilelf> heh
jul 29 23:04:35 <evilelf> abusing of a ball?
jul 29 23:05:57 <-- MrFlex has quit (Quit)
jul 29 23:06:03 <Nanuq> Mr. Elf
jul 29 23:07:18 <Gathond> ufhpc: shortly
jul 29 23:07:48 <ufhpc> Gathond: http://pastebin.com/d35c07ddd
jul 29 23:08:20 <evilelf> Mr. Nuq
jul 29 23:08:25 <evilelf> Nanuq: how goes? How's work?
jul 29 23:08:59 <Nanuq> evilelf: Over?
jul 29 23:09:28 <Gathond> ufhpc: LOL
jul 29 23:09:35 <Gathond> ufhpc: I like:)

<content of pastebin link>
#!/usr/bin/perl



use Switch;

use DBI();

use Text::ParseWords;



# Database DSN and access credentials



$dsn="DBI:mysql:database=test;host=localhost";

$dbuser='test';

$dbpwd='testpw';



$dbh = DBI->connect($dsn, $dbuser, $dbpwd, {'RaiseError' => 1});

$dbh->do("CREATE TEMPORARY TABLE scls (id INT, perm VARCHAR(10), hlinks " .

"INT, user VARCHAR(16), grp VARCHAR(16), filesize INT, month " .

"VARCHAR(3), day INT, yearortime VARCHAR(5), filename VARCHAR(40))");



@lines = `ls -l @ARGV[0]`;



$first_line = @lines[0];



shift(@lines);

for my $a (@lines) {

@line = &shellwords($a);

$dbh->do("INSERT INTO scls (perm, hlinks, user, grp, filesize, month, " .

"day, yearortime, filename)" .

"VALUES ('@line[0]', '@line[1]', '@line[2]', '@line[3]', " .

"'@line[4]', '@line[5]', '@line[6]', '@line[7]', '@line[8]')");

}



$sth = $dbh->prepare("SELECT * FROM scls ORDER BY filesize");

$sth->execute();

while(@linevals = $sth->fetchrow_array) {

foreach(@linevals) {

print "$_ ";

}

print "\n";

}
</content of pastebin link>

Valid XHTML 1.1! This site has been written by Anders Kvist < akv at lnxbx dot dk > - ©2004 Valid CSS!