首页 > 系统相关 >Linux之tr命令

Linux之tr命令

时间:2022-08-29 16:23:03浏览次数:68  
标签:字符 Ctrl -- tr 命令 Linux home

1.tr指令说明

Linux tr 命令用于转换或删除文件中的字符。

tr 指令从标准输入设备读取数据,经过字符串转译后,将结果输出到标准输出设备。

2、tr语法

tr [-cdst][--help][--version][第一字符集][第二字符集]  
tr [OPTION]…SET1[SET2] 

3.参数说明

-c, --complement:反选设定字符。也就是符合 SET1 的部份不做处理,不符合的剩余部份才进行转换
-d, --delete:删除指令字符
-s, --squeeze-repeats:缩减连续重复的字符成指定的单个字符
-t, --truncate-set1:削减 SET1 指定范围,使之与 SET2 设定长度相等
--help:显示程序用法信息
--version:显示程序本身的版本信息

4.字符集合的范围

\NNN 八进制值的字符 NNN (1 to 3 为八进制值的字符)
\\ 反斜杠
\a Ctrl-G 铃声
\b Ctrl-H 退格符
\f Ctrl-L 走行换页
\n Ctrl-J 新行
\r Ctrl-M 回车
\t Ctrl-I tab键
\v Ctrl-X 水平制表符
CHAR1-CHAR2 :字符范围从 CHAR1 到 CHAR2 的指定,范围的指定以 ASCII 码的次序为基础,只能由小到大,不能由大到小。
[CHAR*] :这是 SET2 专用的设定,功能是重复指定的字符到与 SET1 相同长度为止
[CHAR*REPEAT] :这也是 SET2 专用的设定,功能是重复指定的字符到设定的 REPEAT 次数为止(REPEAT 的数字采 8 进位制计算,以 0 为开始)
[:alnum:] :所有字母字符与数字
[:alpha:] :所有字母字符
[:blank:] :所有水平空格
[:cntrl:] :所有控制字符
[:digit:] :所有数字
[:graph:] :所有可打印的字符(不包含空格符)
[:lower:] :所有小写字母
[:print:] :所有可打印的字符(包含空格符)
[:punct:] :所有标点字符
[:space:] :所有水平与垂直空格符
[:upper:] :所有大写字母
[:xdigit:] :所有 16 进位制的数字
[=CHAR=] :所有符合指定的字符(等号里的 CHAR,代表你可自订的字符)

5.tr 实例

5.1 准备文件

cat tr.txt

nux networks are becoming more and more common, 
but scurity is often an overlooked  
issue. Unfortunately, in today’s environment all networks 
are potential hacker targets,  
fro0m tp-secret military research networks to small home LANs.  
Linux Network Securty focuses on securing Linux in a 
networked environment, where the  
security of the entire network needs to be considered
rather than just isolated machines.  
It uses a mix of theory and practicl techniques to 
teach administrators how to install and  
use security applications, as well as how the 
applcations work and why they are necesary. 

5.2 小写字母全部换成大写字母

[root@ecs-76840553 home]# cat tr.txt | tr [a-z] [A-Z]
NUX NETWORKS ARE BECOMING MORE AND MORE COMMON, 
BUT SCURITY IS OFTEN AN OVERLOOKED  
ISSUE. UNFORTUNATELY, IN TODAY’S ENVIRONMENT ALL NETWORKS 
ARE POTENTIAL HACKER TARGETS,  
FRO0M TP-SECRET MILITARY RESEARCH NETWORKS TO SMALL HOME LANS.  
LINUX NETWORK SECURTY FOCUSES ON SECURING LINUX IN A 
NETWORKED ENVIRONMENT, WHERE THE  
SECURITY OF THE ENTIRE NETWORK NEEDS TO BE CONSIDERED
RATHER THAN JUST ISOLATED MACHINES.  
IT USES A MIX OF THEORY AND PRACTICL TECHNIQUES TO 
TEACH ADMINISTRATORS HOW TO INSTALL AND  
USE SECURITY APPLICATIONS, AS WELL AS HOW THE 
APPLCATIONS WORK AND WHY THEY ARE NECESARY. 
[root@ecs-76840553 home]# 

5.3 小写字母全部换成那个大写字母另一种写法

[root@ecs-76840553 home]# cat tr.txt | tr [:lower:]  [:upper:] 
NUX NETWORKS ARE BECOMING MORE AND MORE COMMON, 
BUT SCURITY IS OFTEN AN OVERLOOKED  
ISSUE. UNFORTUNATELY, IN TODAY’S ENVIRONMENT ALL NETWORKS 
ARE POTENTIAL HACKER TARGETS,  
FRO0M TP-SECRET MILITARY RESEARCH NETWORKS TO SMALL HOME LANS.  
LINUX NETWORK SECURTY FOCUSES ON SECURING LINUX IN A 
NETWORKED ENVIRONMENT, WHERE THE  
SECURITY OF THE ENTIRE NETWORK NEEDS TO BE CONSIDERED
RATHER THAN JUST ISOLATED MACHINES.  
IT USES A MIX OF THEORY AND PRACTICL TECHNIQUES TO 
TEACH ADMINISTRATORS HOW TO INSTALL AND  
USE SECURITY APPLICATIONS, AS WELL AS HOW THE 
APPLCATIONS WORK AND WHY THEY ARE NECESARY. 
[root@ecs-76840553 home]# 

5.4 小写字母a-g换成大写,其余不变

[root@ecs-76840553 home]# cat tr.txt | tr [a-g] [A-G]
nux nEtworks ArE BECominG morE AnD morE Common, 
But sCurity is oFtEn An ovErlookED  
issuE. UnFortunAtEly, in toDAy’s EnvironmEnt All nEtworks 
ArE potEntiAl hACkEr tArGEts,  
Fro0m tp-sECrEt militAry rEsEArCh nEtworks to smAll homE LANs.  
Linux NEtwork SECurty FoCusEs on sECurinG Linux in A 
nEtworkED EnvironmEnt, whErE thE  
sECurity oF thE EntirE nEtwork nEEDs to BE ConsiDErED
rAthEr thAn just isolAtED mAChinEs.  
It usEs A mix oF thEory AnD prACtiCl tEChniquEs to 
tEACh ADministrAtors how to instAll AnD  
usE sECurity AppliCAtions, As wEll As how thE 
ApplCAtions work AnD why thEy ArE nECEsAry. 
[root@ecs-76840553 home]# 

 

标签:字符,Ctrl,--,tr,命令,Linux,home
From: https://www.cnblogs.com/joyware/p/16636213.html

相关文章

  • AFNI 步骤4-命令和预处理
    第一部分AFNI命令和uber_subject.py的使用略 第二部分时间矫正在扫描过程中,从第一个切片到最后一个切片之间存在一定的时间差,导致采集到的数据并不是......
  • Docker常用命令
    帮助命令dockerversion    -查看docker版本号信息dockerinfo       -显示docker的系统信息,包括镜像和容器的数量docker--help     -......
  • git命令整理
    gitbranch-a#查看分支gitbranch#*当前分支gitcheckoutdev#切换gitfetch#同步远程分支gitstatus-sgitclonegitpullorigindevgitdiffgitaddgit......
  • delete、drop和truncate三者区别
    delete、drop和truncate三者区别相同点:1、都有删除表的功能;不同点:1、delete、truncate仅仅删除表里面的数据;drop会把表的结构也删除掉2、delete是DML语句,操作完了,还可......
  • linux环境下安装Elasticsearch
    下载Elasticsearch文件这里使用wget命令进行下载wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.4.0-linux-x86_64.tar.gz\wgethtt......
  • Linux下安装oracle 19c
    一、安装前准备1、下载预安装包wgethttp://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm......
  • javascript中的constructor
    1.使用constructor   constructor是Object类型的原型属性,它能够返回当前对象的构造器(类型函数)。利用该属性,可以检测是否复合类型数据的类型,如对象,数组和函数等。v......
  • el-select和el-tree一起用
    html代码<el-form-itemlabel="树型结构"><el-selectv-model="treeData"placeholder="请选择..."style="width:16rem"><el-option:v......
  • 【Traefik二次开发】中间件 Middleware 开发
    本篇只讨论HTTP中间件中间件定义https://doc.traefik.io/traefik/middlewares/overview/Attachedtotherouters,piecesofmiddlewareareameansoftweakingthe......
  • 【Traefik二次开发】服务 Service 开发
    Service定义https://doc.traefik.io/traefik/routing/services/TheServicesareresponsibleforconfiguringhowtoreachtheactualservicesthatwilleventuall......