当前位置: 技术问答>linux和unix
求助:shell 脚本
来源: 互联网 发布时间:2016-10-27
本文导语: cat $file1 | tr -cd '111240-176' > $file2 上面的shell脚本中,tr -cd '111240-176' 是什么意思 | In the shell program we use to remove all non-printable ASCII characters from a text file, we tell the tr command ...
cat $file1 | tr -cd '111240-176' > $file2
上面的shell脚本中,tr -cd '111240-176' 是什么意思
上面的shell脚本中,tr -cd '111240-176' 是什么意思
|
In the shell program we use to remove all non-printable ASCII characters from a text file, we tell the tr command to delete every character in the translation process except for the specific characters we specify. In essence, we filter out the undesirable characters. The tr command we use in our program is shown below:
tr -cd '111240-176' $OUTPUT_FILE
In this command, the variable INPUT_FILE must contain the name of the Solaris file you'll be reading from, and OUTPUT_FILE must contain the name of the output file you'll be writing to. When the -c and -d options of the tr command are used in combination like this, the only characters tr writes to the standard output stream are the characters we've specified on the command line.
Although it may not look very attractive, we're using octal characters in our tr command to make our programming job easier and more efficient. Our command tells tr to retain only the octal characters 11, 12, and 40 through 176 when writing to standard output. Octal character 11 corresponds to the [TAB] character, and octal 12 corresponds to the [LINEFEED] character. The octal characters 40 through 176 correspond to the standard visible keyboard characters, beginning with the [Space] character (octal 40) through the ~ character (octal 176). These are the only characters retained by tr -- the rest are filtered out, leaving us with a clean ASCII file.
tr -cd '111240-176' $OUTPUT_FILE
In this command, the variable INPUT_FILE must contain the name of the Solaris file you'll be reading from, and OUTPUT_FILE must contain the name of the output file you'll be writing to. When the -c and -d options of the tr command are used in combination like this, the only characters tr writes to the standard output stream are the characters we've specified on the command line.
Although it may not look very attractive, we're using octal characters in our tr command to make our programming job easier and more efficient. Our command tells tr to retain only the octal characters 11, 12, and 40 through 176 when writing to standard output. Octal character 11 corresponds to the [TAB] character, and octal 12 corresponds to the [LINEFEED] character. The octal characters 40 through 176 correspond to the standard visible keyboard characters, beginning with the [Space] character (octal 40) through the ~ character (octal 176). These are the only characters retained by tr -- the rest are filtered out, leaving us with a clean ASCII file.