Shell/Bash代码信息

运行结果
教程手册
代码仓库
极速运行
交互输入
极速运行模式,不支持键盘输入语句但是拥有更高的运行速度,输出简洁明了 。 点击编辑器上方的运行按钮即刻体验吧。
以下是用户最新保存的代码
shell脚本方式启动Tomcat服务 发布于:2021-03-02 13:59 九九乘法表 发布于:2021-02-24 19:27 shell 基本用法记录 发布于:2021-01-29 11:02 监控cpu、内存,并且告警 发布于:2021-02-04 16:02 接口测试shell脚本 发布于:2021-01-13 16:56 自动生成openssl证书 发布于:2021-01-12 14:23 curl auth ter global 发布于:2020-09-22 11:32 截取命令结果/后面字符 发布于:2020-09-02 08:55 linux- 1.查看系统信息 发布于:2020-08-06 16:26 v2ray-shell 发布于:2020-09-21 16:13 ubuntu 常用命令 发布于:2020-02-22 17:09 又来测试了 发布于:2019-12-25 10:39 The first project of shell 发布于:2019-05-17 14:51 Shell/Bach 时间戳 发布于:2019-04-03 14:17 linux命令查询cpu、内存信息 发布于:2019-02-24 18:59 [更多]
显示目录

tr 命令-转换/删除文件字符

tr命令

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 显示程序本身的版本信息

字符集合的范围:

\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,代表可自订字符)

实例

将文件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.
由JSRUN为你提供的Shell/Bash在线工具
        JSRUN提供的Shell/Bash在线运行,Shell/Bash 在线编译工具,基于linux操作系统环境提供线上编译和线上运行,具有运行快速,运行结果与常用开发、生产环境保持一致的特点。

title

使用此草稿 删除草稿

皮肤:

运行模式:

嵌入代码 iframe嵌入: