Re: 'sort' command-alternative?
Re: 'sort' command-alternative?
- Subject: Re: 'sort' command-alternative?
- From: bill fancher <email@hidden>
- Date: Fri, 4 Oct 2002 12:24:48 -0700
On Friday, October 4, 2002, at 12:45 AM, John Delacour wrote:
Here's a case-insensitive way, which also omits the empty lines:
Or you can just use sort's "-f" flag for case insensitive sorts:
set text item delimiters to (ASCII character 10)
tell application "Finder" to set theList to (name of processes) as
string
set text item delimiters to {""}
do shell script ("echo '" & theList as string & "'| sort -f")
Other handy flags include "-u" to get a sorted list of unique items and
"-r" for reverse sort. You can also easily specify a field separator
and sort by field. See the man page for details (do shell script "man
sort|col -b").
The above doesn't address the problem noted by Randal L. Schwartz
concerning breakage when process names contain single quotes. That's
not just a Perl thing.
A general rant for the non-unix-insane:
One nice thing about command line tools like sort is that they're
language neutral in much the same way osaxen are. You can run them from
AppleScript, Perl, Tcl, Python, JavaScript, Ruby, etc. In that spirit,
try:
do shell script "ls /bin /sbin /usr/bin /usr/sbin | wc -l"
to get a count of all the shiny new "osaxen" that BSD provides: 810
OMM. (BTW, the above just lists contents of "well known" directories
and pipes the result to wc. With the -l flag, wc (word count) counts
lines in its input and returns the result.)
You can compress/decompress files, generate a calendar, change
passwords, compare files, copy folder hierarchies,... After more than
30 years of *NIX use, there's a command for virtually every basic
function. The biggest problem is often figuring out which one does what
you want. (The "apropos" command can be a big help there.)
Just to give an idea of the power you now have, here's a script that
"extends" AppleScript on the fly. It changes the working directory to
/tmp, creates a C source file there (hello.c), compiles it into a brand
new custom tool (hello), runs the new tool, and returns its output,
which is then displayed in a dialog. It requires the (free) developer
tools. If you've got AS Studio installed, you're all set.
do shell script paragraphs of "
cd /tmp
echo 'main(){printf(\"Hello, '`whoami`'!\");return 0;}'>hello.c
cc hello.c -o hello
./hello
" as string
display dialog the result
-- Now we can run the tool any time we like
display dialog (do shell script "/tmp/hello") & " (Again)"
--
bill
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.