Linux 我可以使用 awk 将所有小写字母转换为大写字母吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14021899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:06:26  来源:igfitidea点击:

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

linuxbashawk

提问by Yishu Fang

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

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

采纳答案by Rubens

Try this:

尝试这个:

awk '{ print toupper(
awk '{ print toupper(
< yourMIXEDCASEfile.txt awk '{print toupper(
tr a-z A-Z < input
)}' > yourUPPERCASEfile.txt
) }' yourfile.txt
) }' <<< "your string"

Using a file:

使用文件:

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

回答by Mats Petersson

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)

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

回答by Silviu

Something like

就像是

$ echo mix23xsS | awk '{ print toupper(
perl -ne 'print uc()' file
) }' MIX23XSS

回答by William Pursell

You can use awk, but tris the better tool:

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

perl -ne 'print lc()' file

or

或者

##代码##

回答by basos

Try this:

尝试这个:

##代码##

回答by Chris Koknat

If Perl is an option:

如果 Perl 是一个选项:

##代码##
  • -nloop around input file, do not automatically print line
  • -eexecute the perl code in quotes
  • uc()= uppercase
  • -n循环输入文件,不自动打印行
  • -e在引号中执行 perl 代码
  • uc()= 大写

To print all lowercase:

要打印所有小写:

##代码##