Can I use awk to convert all the lower-case letters into upper-case?

LinuxBashAwk

Linux Problem Overview


I have a file mixed with lower-case letters and upper-case letters, can I use awk to convert all the letters in that file into upper-case?

Linux Solutions


Solution 1 - Linux

Try this:

awk '{ print toupper($0) }' <<< "your string"

Using a file:

awk '{ print toupper($0) }' yourfile.txt

Solution 2 - Linux

You can use awk, but tr is the better tool:

tr a-z A-Z < input

or

tr [:lower:] [:upper:] < input

Solution 3 - Linux

Try this:

$ echo mix23xsS | awk '{ print toupper($0) }'
MIX23XSS

Solution 4 - Linux

Something like

< yourMIXEDCASEfile.txt awk '{print toupper($0)}' > yourUPPERCASEfile.txt

Solution 5 - Linux

You mean like this thread explains: http://www.unix.com/shell-programming-scripting/24320-converting-file-names-upper-case.html (Ok, it's about filenames, but the same principle applies to files)

Solution 6 - Linux

If Perl is an option:

perl -ne 'print uc()' file
  • -n loop around input file, do not automatically print line
  • -e execute the perl code in quotes
  • uc() = uppercase

To print all lowercase:

perl -ne 'print lc()' file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYishu FangView Question on Stackoverflow
Solution 1 - LinuxRubensView Answer on Stackoverflow
Solution 2 - LinuxWilliam PursellView Answer on Stackoverflow
Solution 3 - LinuxbasosView Answer on Stackoverflow
Solution 4 - LinuxSilviuView Answer on Stackoverflow
Solution 5 - LinuxMats PeterssonView Answer on Stackoverflow
Solution 6 - LinuxChris KoknatView Answer on Stackoverflow