50

我有一个混合了小写字母和大写字母的文件,我可以使用awk该文件中的所有字母转换为大写字母吗?

4

6 回答 6

94

试试这个:

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

使用文件:

awk '{ print toupper($0) }' yourfile.txt
于 2012-12-24T13:16:15.597 回答
20

您可以使用awk,但tr它是更好的工具:

tr a-z A-Z < input

或者

tr [:lower:] [:upper:] < input
于 2012-12-24T13:17:31.230 回答
3

就像是

< yourMIXEDCASEfile.txt awk '{print toupper($0)}' > yourUPPERCASEfile.txt
于 2012-12-24T13:16:25.973 回答
3

试试这个:

$ echo mix23xsS | awk '{ print toupper($0) }'
MIX23XSS
于 2012-12-24T13:18:41.060 回答
2

你的意思是像这个线程解释: http ://www.unix.com/shell-programming-scripting/24320-converting-file-names-upper-case.html (好的,它是关于文件名,但同样的原则适用于文件)

于 2012-12-24T13:15:33.253 回答
0

如果 Perl 是一个选项:

perl -ne 'print uc()' file
  • -n循环输入文件,不自动打印行
  • -e在引号中执行 perl 代码
  • uc()= 大写

打印全部小写:

perl -ne 'print lc()' file
于 2015-09-11T00:47:40.820 回答