Re: Change lower case (55 Views)
Reply
Valued Contributor
Posts: 1,372
Registered: ‎12-08-1999
Message 1 of 10 (55 Views)
Accepted Solution

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
Valued Contributor
Posts: 89
Registered: ‎11-05-2000
Message 2 of 10 (55 Views)

Re: Change lower case

Robert,

Use

cat file | tr 'a-z' 'A-Z'
Outstanding Contributor
Posts: 16,207
Registered: ‎11-03-1996
Message 3 of 10 (55 Views)

Re: Change lower case

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

Do a man on tr.


Pete

Pete
Honored Contributor
Posts: 4,470
Registered: ‎02-13-2002
Message 4 of 10 (55 Views)

Re: Change lower case

Robert,
tr "[:lower:]" "[:upper:]" file2
Regards
Honored Contributor
Posts: 13,846
Registered: ‎06-21-2000
Message 5 of 10 (55 Views)

Re: Change lower case

Yet another different way of doing it:

# awk '{print toupper($0)}' filename > filename.new
Honored Contributor
Posts: 4,470
Registered: ‎02-13-2002
Message 6 of 10 (55 Views)

Re: Change lower case

Pete,
I believe your [:upper] and [:lower] are the wrong way round ;-)
Regards
Valued Contributor
Posts: 146
Registered: ‎04-05-2001
Message 7 of 10 (55 Views)

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!
Valued Contributor
Posts: 146
Registered: ‎04-05-2001
Message 8 of 10 (55 Views)

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!
Valued Contributor
Posts: 146
Registered: ‎04-05-2001
Message 9 of 10 (55 Views)

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!
Honored Contributor
Posts: 508
Registered: ‎12-11-2004
Message 10 of 10 (55 Views)

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
:-)
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.