Here I specified set2 as the space character (Web page design)
Tuesday, August 21st, 2007Here I specified set2 as the space character because words separated by the characters in set1 need to remain separate after the punctuation is removed. Notice that the characters [ and ] are given as [ and ]. As you will see later in this chapter, these two characters have a special meaning in tr and need to be escaped using the backslash character ( ) in order to be handled correctly. At this point most of the words are separated by spaces, but some of the words are separated by tabs and newlines. To get an accurate count, all the words should be separated by spaces, so you need to covert all tabs and newlines to spaces: $ tr ‘!?”:;[]{}(),.tn’ ‘ ‘ < /home/ranga/docs/ch15.doc The next step is to transliterate all capitalized versions of words to a lowercase version because the words To and to, The and the, and Files and files are really the same word. To do this, you tell tr to change all the capital characters 'A-Z' into lowercase characters 'a-z' as follows: $ tr '!?":;[]{}(),.tn' ' ' < /home/ranga/docs/ch15.doc | tr 'A-Z' 'a-z' I broke the command into two lines, with the pipe character as the last character in the first line so that the shell does the right thing and uses the next line as the command to pipe to. This makes it easier to read and cut and paste, also. Note - Differences between tr versions In this example, you are using a single space for set2. Most versions of tr interpret this to mean transliterating all the characters in set1 to a space. Some versions of tr do not do this. You can determine whether your tr works in this manner using the test code: $ echo "Hello, my dear!" | tr ',!' ' ' Most versions of tr produce the following output: Hello my dear Some versions produce the following output instead: Hello my dear! To obtain the desired behavior from these versions of tr, make sure that set1 and set2 have the same number of characters. In this case, set2 needs to contain two spaces: $ echo "Hello, my dear!" | tr ',!' ' ' In the case of the sample problem, set2 would need to contain 15 spaces.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.