cancel
Showing results for 
Search instead for 
Did you mean: 

Change lower case

SOLVED
Go to solution
Nobody's Hero
Valued Contributor

Change lower case

Is there a script or utility that allows me to change an ascii file from lower case to upper case?

The entire file is lower case and I want it to be upper case.
UNIX IS GOOD
9 REPLIES
Highlighted
Rajeev Tyagi
Valued Contributor
Solution

Re: Change lower case

Robert,

Use

cat file | tr 'a-z' 'A-Z'
Pete Randall
Outstanding Contributor

Re: Change lower case

tr -s '[:upper:]' '[:lower:]'

Do a man on tr.


Pete

Pete
Peter Godron
Honored Contributor

Re: Change lower case

Robert,
tr "[:lower:]" "[:upper:]" file2
Regards
Patrick Wallek
Honored Contributor

Re: Change lower case

Yet another different way of doing it:

# awk '{print toupper($0)}' filename > filename.new
Peter Godron
Honored Contributor

Re: Change lower case

Pete,
I believe your [:upper] and [:lower] are the wrong way round ;-)
Regards
Dani Seely
Valued Contributor

Re: Change lower case

Hey Robert,
Thanks for posting this question. I've just learned the easy way of doing this. I've not needed to do an entire file before, just certain sections within a file. I've done this manually by putting my cursor over the first letter to change to uppercase (or this works also for lowercase) and holding the shift key down and pressing the ~ (tilde) key. Holding these keys down changes the case from lower to upper or upper to lower (depending on the current case) until I release the keys.

Again, thanks for posting your question.
Together We Stand!
Dani Seely
Valued Contributor

Re: Change lower case

Hey Robert,
I couldn't get this to work:
# cat file | tr 'a-z' 'A-Z'

but I could get this to work:
# cat file | tr -s '[:lower:]' '[:upper:]'

Again, thanks.
Together We Stand!
Dani Seely
Valued Contributor

Re: Change lower case

Hey Robert,
Sorry, forgot the complete syntax for converting a file from lowercase to uppercase ...

# cat | tr -s '[:lower:]' '[:upper:]' >
Together We Stand!
Biswajit Tripathy
Honored Contributor

Re: Change lower case

If you want to do this in C, here is it:

--- File toupper.c ----
#include
#include
int main ()
{
for (;!feof(stdin);)
fputc (toupper(fgetc (stdin)), stdout);
return 0;
}
---- End ---
Save above file in toupper.c and compile.
# cc toupper.c -o toupper

Execute it as:
# cat you_file | toupper

- Biswajit
:-)