Changing Case



What standard app can be used to change the selected text to all lower case?
None of: TextEdit, Pages, Xcode, OmniOutlinerPro.
What about the BSD tools? Doesn’t look like vi can do it, no obvious tools in the man pages.
Sed? Awk? Suggestions?




JC I thought about doing this in Perl, because I’m a dork that way. awk is the right tool for the job, though. And it’s easy.

The -f technically implores awk to take input from a file, but I find that the script will still take STDIO through pipes on the command line, making this script rather multipurpose.

#!/usr/bin/awk -f
{ print tolower($0); }

Sorry, we don’t give out iTunes for one liners. Unless it’s a really cool one-liner. Then we’ll think about it. This one’s t3h l4me. For the record, UNIX commands (“BSD tools”) are never capitalized, even when they lead a sentance.

codepoet So, to be more clear: take the above one-liner and save it in a file, mark it executable, and then invoke it. I saved it as tolower in my personal bin directory and then you’d use it with a filename as input:

./tolower filename.txt > filename-lower.txt


slip said

select text, right click -> convert -> to Lowercase

or ctrl-shift U

aricart said

While the command solutions works great, wouldn't it be better if you could do the same without resorting to the shell?

Well you can, if you use my UnixServices service provider, simply select text, go to the Services menu and choose whatever formatting command you have defined.

And yes, you read it right, the app is fully extensible, you define the commands you want available, so you can map to any command line tool to process text in any way you'd like. Best of all, its priced to sell, the app is free. Enjoy.

JC said
JC's picture

Like most things on the command line, There’s More Than One Way to Do It.

Adam Knight's picture

Yes, but does vim do streams from the shell? I’ve never seen it used as such…

cp

awk works, but the more specific tool is tr:

tr '[:upper:]' '[:lower:]' < filename.txt

Syndicate content