Linux 中sed命令的大小写转换

 

001、 小写转换为大写

[root@PC1 test]# ls
[root@PC1 test]# echo {a..g}
a b c d e f g
[root@PC1 test]# echo {a..g} | sed 's/[a-z]/\U&/g'   ## \U表示将后边的字母转换为大写(U:uppercase); &表示匹配到的字符; \U或者\u都可以
A B C D E F G

image

 。

 

002、大写转换为小写

[root@PC1 test]# ls
[root@PC1 test]# echo {A..G}
A B C D E F G
[root@PC1 test]# echo {A..G} | sed 's/[A-Z]/\L&/g'    ## \L 表示将后边的字符转换为小写(L:lowercase); &表示匹配到的字符;\L或者\l均可。
a b c d e f g

image

 。

 

003、\E选项

[root@PC1 test]# ls
[root@PC1 test]# echo hello world
hello world
[root@PC1 test]# echo hello world | sed 's/\(hello\)/\U\1\E/'     ## \1表示预存储空间,也就是匹配到的第一部分,\E表示终止; (E:end)
HELLO world

image

 。

 

posted @ 2026-01-02 00:14  小鲨鱼2018  阅读(3)  评论(0)    收藏  举报