Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

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?


Dave's Answer:

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 Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

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 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]