
Where can I find the 'rev' utility for Solaris?Dave, I am a Sun Solaris sysadmin and really liked your book Wicked Cool Shell Scripts. However, I don't seem to find the "rev" utility on any of my Sun servers running Solaris 2.6, 7, 8, and even 9. I couldn't find it on the sunfreeware.com site either. Could you tell me where I can find it?
Thanks for your note. I don't really know where to find the "real" rev utility, but it's so darn simple that I whipped out a rudimentary C version of it for you. In case you, the reader, doesn't know what this amusing little utility does, it reverses the order of characters in a line, so Wicked Cool would become looC dekciW. Before I present the code, I want to invite people to pop over to my business weblog The Intuitive Life, where Sun Microsystems President Jonathan Schwartz and I are currently discussing the state of Solaris and the future of Solaris 10 in the topic Sun complains, IBM won't port apps to Solaris 10. Please feel free to add your own comments about Solaris and Sun's worldwide strategy there too! Here's the rev program, in C:
/** rudimentary version of rev.c that only works with pipes **/
#include <stdio.h>
main()
{
char linebuffer[1024];
int i;
while (fgets(linebuffer, 1024, stdin) != NULL) {
for (i=strlen(linebuffer)-1; i >= 0; i--)
putchar(linebuffer[i]);
}
putchar('\n');
}
The real rev program can also accept filenames, but since I only use rev in pipes in the book, I figured that this version should cover your needs. To compile and create a runnable binary, copy and paste the above into a text editor, then save it as "rev.c". Now do this: $ cc rev.c -o rev $ echo "alias rev=$PWD/rev" >> ~/.profile $ This will give you a runnable program and add an alias for 'rev' to your .profile (I assume you're using Bash as your login shell) so that when you log in in the future, you'll be able to just type "rev" and get to your binary. You could also move it into a directory that's in your PATH (I use ~/bin for my own custom apps, for example), which is probably a better solution, but slightly more complicated. That should get you going. When it's working you can do delightful and useful things like this: $ ls -l | rev | head -5 706 latot /TDA 05:10 02 ceD 215 resuv tnitd 2 x-rx-rxwrd /29.0-tniL-LMTH 2002 12 yaM 215 resuv tnitd 6 x-rx-rxwrd /liaM 12:41 82 ceD 215 resuv tnitd 2 ------xwrd Ahhh... ain't the command line grand?! :-)
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
Unix and Linux Help
(Article 3872)
Tagged: Previous: Can the Google AdSense Search Tool background be changed? Next: What's an RSS Aggregator? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader. Dave - I run sunfreeware.com which is mentioned in this post about rev. I also own your book Wicked Cool Shell Scripts. I would be happy to make precompiled versions for Solaris of any programs like rev you think would be of use to Solaris users. If you or your Solaris users would like to give me suggestions, I can easily do this. Posted by: Steve Christensen at February 2, 2005 6:50 AMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Industry News and Trade Shows Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Book Links
|