linux 中实现大小写转换

 

1、tr实现

a、

复制代码
[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                          ## 测试文本
ab cd EF
Gh ij KL
[root@PC1 test1]# cat a.txt | tr "A-Z" "a-z"         ## 全部转换为小写
ab cd ef
gh ij kl
[root@PC1 test1]# cat a.txt | tr "a-z" "A-Z"         ## 全部转换为大写
AB CD EF
GH IJ KL
复制代码

 

b、大小写相互转换

[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                           ## 测试文本
ab cd EF
Gh ij KL
[root@PC1 test1]# cat a.txt | tr "a-zA-Z" "A-Za-z"    ## 大小写相互转换
AB CD ef
gH IJ kl

 

 

2、awk实现

复制代码
[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                             ## 测试文本
ab cd EF
Gh ij KL
[root@PC1 test1]# awk '{print toupper($0)}' a.txt       ## 全部转换为大写
AB CD EF
GH IJ KL
[root@PC1 test1]# awk '{print tolower($0)}' a.txt       ## 全部转换为小写
ab cd ef
gh ij kl
复制代码

 

3、sed实现

复制代码
[root@PC1 test1]# ls
a.txt
[root@PC1 test1]# cat a.txt                      ## 测试数据
ab cd EF
Gh ij KL
[root@PC1 test1]# sed 's/[a-z]/\U&/g' a.txt      ## 全部转换为大写
AB CD EF
GH IJ KL
[root@PC1 test1]# sed 's/[A-Z]/\L&/g' a.txt      ## 全部转换为小写
ab cd ef
gh ij kl
复制代码

 。

 

posted @   小鲨鱼2018  阅读(220)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-02-06 linux 中提取以指定字符开头的数据^和\<的区别
2021-02-06 python的严格缩进可以避免else悬挂
2021-02-06 python中assert语句
2021-02-06 python 小甲鱼猜数字游戏
2021-02-06 python中random模块引入随机数
2021-02-06 c语言中利用三维数组计算成绩总分数
2021-02-06 c语言中求课程总分、平均分。学生总分及平均分
点击右上角即可分享
微信分享提示