Thursday, August 09, 2007

Capitalize Strings in UNIX

There might be times when you need to CAPITALIZE everything. The capitalize command handles this task well. Here is an example of its use.

Capitalize entire contents of a script or plain file
# cat testme | /usr/openwin/bin/capitalize -u
#!/BIN/KSH

IF [ $# = 0 ]; THEN
ECHO ADD AN ARGUMENT LIST
EXIT
FI
...

# cat Tech@Sakana | /usr/openwin/bin/capitalize -u
YOU CAN USE CAPITALIZE COMMAND OR THE UNIX TR COMMAND, WHICH WAS SUGGESTED BY STEPHANE KATTOOR

Capitalize the output of a command
# date | /usr/openwin/bin/capitalize -u
THU AUG 9 22:56:16 KST 2007

To lowercase , read this post: Output strings to lowercase

3 comments:

Anonymous said...

funny...i was doing it with a loop

Anonymous said...

For those working on minimised systems where capitalize doesn't exist, a more portable solution is to use tr:

tr "[:lower:]" "[:upper:]"

Stephane said...

and for those having a tr not knowing about classes : tr "[a-z]" "[A-Z]"

:)