Latest web development tutorials

Linux tr command

Linux command Daquan Linux command Daquan

Linux tr command to convert the file or delete the characters.

tr command input device to read data from the standard, after a string of translation, the results to the standard output device.

grammar

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

Parameter Description:

  • -c, --complement: anti-election character set. That is not in line with SET1 part, and the remaining part of the non-compliance before conversion
  • -d, --delete: delete character instruction
  • Reduced continuously repeated single character to the specified character: -s, --squeeze-repeats
  • -t, --truncate-set1: cut SET1 specified range, so as to set the length equal to SET2
  • --help: Display program usage information
  • --version: display program version information itself

Range of characters sets:

  • \ Character octal value NNN NNN (1 to 3 octal value of the character)
  • \\ Backslash
  • \ A Ctrl-G Ringtones
  • \ B Ctrl-H Backspace
  • \ F Ctrl-L Traveling feed
  • \ N Ctrl-J new row
  • \ R Ctrl-M Enter
  • \ T Ctrl-I tab key
  • \ V Ctrl-X horizontal tabs
  • CHAR1-CHAR2: The characters range from CHAR1 to CHAR2 designation of the specified range in ASCII order basis only from small to big, not descending.
  • [CHAR *]: This is the SET2 specific setting, the function is repeated the specified character to the same length as far SET1
  • [CHAR * REPEAT]: This is the SET2 specific setting, the function is repeated a specified number of characters to set up REPEAT (REPEAT figures collected 8 binary system calculated at zero start)
  • [: Alnum:]: all alphabetic characters and numbers
  • [: Alpha:]: all alphabetic characters
  • [: Blank:]: all horizontal space
  • [: Cntrl:]: all control characters
  • [: Digit:]: All figures
  • [: Graph:]: all printable characters (not including spaces)
  • [: Lower:]: all lowercase letters
  • [: Print:]: all printable characters (including spaces)
  • [: Punct:]: All punctuation characters
  • [: Space:]: all horizontal and vertical spaces
  • [: Upper:]: all uppercase letters
  • [: Xdigit:]: All hexadecimal number system
  • [= CHAR =]: all consistent with the specified character (the equal sign in the CHAR, represent your customizable character)

Examples

The file testfile in all lowercase letters to uppercase letters, then, use the following command:

cat testfile |tr a-z A-Z 

testfile file reads as follows:

$ 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. 

After using the tr command to convert the case to give the following output:

$ 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. 

Case conversion parameters to achieve, can also [:: lower] [upper]. For example, use the following command:

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

The output is as follows:

$ 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. 

Linux command Daquan Linux command Daquan