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

后端 未结 6 1222
醉话见心
醉话见心 2020-12-29 01:38

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?

相关标签:
6条回答
  • 2020-12-29 01:40

    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
    
    0 讨论(0)
  • 2020-12-29 01:42

    Try this:

    $ echo mix23xsS | awk '{ print toupper($0) }'
    MIX23XSS
    
    0 讨论(0)
  • 2020-12-29 01:43

    Something like

    < yourMIXEDCASEfile.txt awk '{print toupper($0)}' > yourUPPERCASEfile.txt
    
    0 讨论(0)
  • 2020-12-29 01:52

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

    tr a-z A-Z < input
    

    or

    tr [:lower:] [:upper:] < input
    
    0 讨论(0)
  • 2020-12-29 02:02

    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)

    0 讨论(0)
  • 2020-12-29 02:04

    Try this:

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

    Using a file:

    awk '{ print toupper($0) }' yourfile.txt
    
    0 讨论(0)
提交回复
热议问题