博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux命令(42):tr命令
阅读量:6342 次
发布时间:2019-06-22

本文共 2455 字,大约阅读时间需要 8 分钟。

Linux tr命令

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

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

语法:

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

参数说明:

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

实例

将文件testfile中的小写字母全部转换成大写字母,此时,可使用如下命令:

cat testfile |tr a-z A-Z

testfile文件中的内容如下:

$ cat testfile         #testfile原来的内容  Linux 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.

使用 tr 命令大小写转换后,得到如下输出结果:

$ cat testfile | tr a-z A-Z #转换后的输出 LINUX 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, FROM 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.

大小写转换,也可以通过[:lower][:upper]参数来实现。例如使用如下命令:

cat testfile |tr [:lower:] [:upper:]

输出结果如下:

$ cat testfile | tr [:lower:] [:upper:] #转换后的输出 LINUX 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, FROM 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.
 

转载地址:http://sxkla.baihongyu.com/

你可能感兴趣的文章
property函数
查看>>
数论 - 组合数学 + 素数分解 --- hdu 2284 : Solve the puzzle, Save the world!
查看>>
.Net 从零开始构建一个框架之基本实体结构与基本仓储构建
查看>>
C#核编之内建数据类型
查看>>
Oracle运算符收录(易忘记,但是又很重要的运算符)
查看>>
POJ 2062 Card Game Cheater
查看>>
'ascii' codec can't decode byte 0xd6 in position 0
查看>>
TPVJ水题
查看>>
OWINS是什么(转载)
查看>>
在一台电脑访问另一台电脑的mysql数据库
查看>>
指针数组与数组指针
查看>>
python之MySQL学习——数据操作
查看>>
Quartz定调度简单案例
查看>>
关于微信小程序 modal弹框组件的介绍
查看>>
给一系列的div中的第一个添加class
查看>>
centos6.8 安装jenkins
查看>>
vue-cli3.0+node.js+axios跨域请求session不一样的问题
查看>>
C#发送DKIM签名的邮件
查看>>
python中获取字典的key列表和value列表
查看>>
Windows8中使用IE8等低版本浏览器
查看>>