Industry guru Dave Taylor offers tech support on technical and business topics, including iPhone, iPod, Microsoft Windows, Sony PSP, cellphones, online advertising, CSS, Web design, business, Unix, Linux, SEO, Mac OS X, and shell script programming.     


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?! :-)


Related Unix and Linux Help articles:
✔   Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔   Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
✔   Can I script renaming files based on an XML data map?
I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing...
✔   Test for valid numbers in a Bash shell script?
In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying...
✔   Review: iSSH for the iPad/iPhone
If you're running an online business like I am, there are times when you need to connect and log in to the server...

Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
    Enter your name: and your email addr:  









Reader Comments To Date: 1

Steve Christensen said, on February 2, 2005 6:50 AM:

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.

Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

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











I will never send you any unsolicited email. Ever.






Check This Out Too...

 
Look for Answers
Need Help? Ask Dave Taylor!
Powered By
Linux Journal: Free Issue!


Follow Me on Pinterest

Find Me on Google+
ADT on G+
© 2002 - 2013 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. Further, 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. My lawyer says "Thanks".
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.