Linux基础——tr指令

一、tr概述

tr用于对文本进行字符基本转换或删除

二、tr范例

# 将多个空格转换为一个
[root@harbor ~]# echo "a b c 1 2" > test.txt [root@harbor ~]# cat test.txt a b c 1 2 [root@harbor ~]# cat test.txt | tr -s ' ' a b c 1 2

# 删除多个特殊字符 [root@harbor ~]# echo 'a!b#c*d(' > test.txt [root@harbor ~]# cat test.txt a!b#c*d( [root@harbor ~]# cat test.txt | tr -d '!#*(' abcd

# 文本大写字母转为小写 [root@harbor
~]# echo 'abcd' > test.txt [root@harbor ~]# cat test.txt | tr '[:lower:]' '[:upper:]' ABCD

# 文本小写字母转为大写 [root@harbor
~]# echo 'ABCD' > test.txt [root@harbor ~]# cat test.txt | tr '[:upper:]' '[:lower:]' abcd

 

posted on 2025-04-07 16:03  gkhost  阅读(48)  评论(0)    收藏  举报

导航