perl sort

J

Jan Burdil

Hello,
how can I replace * with some command like cat file, ls -l in line

perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

Thank you
Jan Burdil
 
J

J. Gleixner

Jan said:
Hello,
how can I replace * with some command like cat file, ls -l in line

perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

You'd use your editor, or your arrow keys, move the cursor to '*',
remove '*', and insert whatever you like.

Maybe explaining what you want to do and what you tried would get you a
better answer.
 
B

Ben Morrow

Quoth "Jan Burdil said:
Subject: perl sort

Please use a sensible Subject. You question has nothing to do with
sorting.
how can I replace * with some command like cat file, ls -l in line

perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

You can skip the last "\n" by adding a -l to your commandline.
You can skip the join by putting

$, = "\n";

before the print statement, though that's arguably no simpler in this
case.

Read the section on qx in perldoc perlop.

Alternatively, you can probably do what you want from within Perl,
without calling an external command.

Ben
 
U

usenet

Jan said:
how can I replace * with some command like cat file, ls -l in line
perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'

perl -e 'print join "\n", sort { -M $b <=> -M $a } `ls -l`,"\n"'

But I find it hard to believe you REALLY want to do that... that's
nutty. There are far better ways to do that (either in Perl or using
plain shell commands).
 
J

Jan Burdil

when I try
perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
bb
xx
aa
Mail
mail
yy
unrar
tmp
curl.txt
abc

my files are sorted by date. And I need to sort lines from curl command.
curl ftp://1.1.1.1 give me
-rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
-rwx------ 1 honza users 52 May 31 21:54 bb
drwx------ 2 honza users 512 Aug 22 10:54 mail

And I would like the result to be sorted by date.

I try replace <*> with command curl ftp://1.1.1.1 like this
perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
ftp://1.1.1.1`,"\n"'
but this doesn't work

Jan Burdil
 
U

usenet

Jan said:
my files are sorted by date. And I need to sort lines from curl command.
curl ftp://1.1.1.1 give me

Somtimes the shell way is the easier way. for example:

ls -l |sort -k 1.37

(see also the -t flag of sort)
 
P

Peter J. Holzer

Jan Burdil said:
And I need to sort lines from curl command.
curl ftp://1.1.1.1 give me
-rw-r--r-- 1 honza users 414 Sep 22 12:16 curl.txt
-rwx------ 1 honza users 52 May 31 21:54 bb
drwx------ 2 honza users 512 Aug 22 10:54 mail

And I would like the result to be sorted by date. [...]
like this
perl -e 'print join "\n", sort { -M $b <=> -M $a } `curl
ftp://1.1.1.1`,"\n"'
[...]

You need to arrange for $a and $b to contain filenames,

How would this help? He needs to sort lines which contain a text
representation of a date by this date. -M doesn't do that, so he
shouldn't use -M but extract the date from each line and convert it to a
comparable value (e.g., seconds since the epoch, or yyyy-mm-ddThh:mm).
HTTP::Date may be helpful.

Another way might be to ditch curl in favour of Net::FTP. I haven't
looked at it, but I expect it to contain a function to parse directory
listings from FTP servers.

hp
 
J

Jan Burdil

this command cort the output, but not good

ls -l |sort -k 1.37
drwx------ 2 honza users 512 Aug 22 10:54 mail
-rwx------ 1 honza users 54 Jun 14 11:29 aa
-rwx------ 1 honza users 832 Sep 5 19:35 yy
-rwx------ 1 honza users 52 May 31 21:54 bb

....
Jan Burdil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top