linux中将所有的小写字符串全部转换为大写

 

001、tr

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt     ## 测试文本
aa BB cc dd
ee FF jj kk
ll mm NN RR
[root@PC1 test]# cat a.txt | tr 'a-z' 'A-Z'     ## 将所有的小写字符全部转换为大写字符
AA BB CC DD
EE FF JJ KK
LL MM NN RR

image

 。

 

02、awk

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
aa BB cc dd
ee FF jj kk
ll mm NN RR
[root@PC1 test]# cat a.txt | awk '{print toupper($0)}'
AA BB CC DD
EE FF JJ KK
LL MM NN RR

image

 .

 

03、sed

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
aa BB cc dd
ee FF jj kk
ll mm NN RR
[root@PC1 test]# cat a.txt | sed 's/.*/\U&/'
AA BB CC DD
EE FF JJ KK
LL MM NN RR

image

 

04、echo

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
aa BB cc dd
ee FF jj kk
ll mm NN RR
[root@PC1 test]# cat a.txt | while read i; do echo ${i^^}; done
AA BB CC DD
EE FF JJ KK
LL MM NN RR

image

 。

 

posted @ 2025-08-28 14:48  小鲨鱼2018  阅读(17)  评论(0)    收藏  举报