zoukankan      html  css  js  c++  java
  • linux命令(42):tr命令

    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 todays 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 TODAYS 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 TODAYS 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.
     
  • 相关阅读:
    bzoj 4451 : [Cerc2015]Frightful Formula FFT
    bzoj 3928: [Cerc2014] Outer space invaders
    HDU 5306 线段树
    bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形
    bzoj 4519: [Cqoi2016]不同的最小割 最小割树
    bzoj : 4504: K个串 区间修改主席树
    bzoj 4332:JSOI2012 分零食
    bzoj 2595 : [Wc2008]游览计划
    poj 3683 Priest John's Busiest Day
    bzoj 1823: [JSOI2010]满汉全席 && bzoj 2199 : [Usaco2011 Jan]奶牛议会 2-sat
  • 原文地址:https://www.cnblogs.com/lovychen/p/7402688.html
Copyright © 2011-2022 走看看