1 00:00:06,480 --> 00:00:09,100 - If you want an easy command-line based utility 2 00:00:10,167 --> 00:00:13,170 to treat text, you might like tr. 3 00:00:13,170 --> 00:00:14,550 What is tr about? 4 00:00:14,550 --> 00:00:16,560 Well, tr stands for translate, 5 00:00:16,560 --> 00:00:19,620 and it allows you to translate sets of characters 6 00:00:19,620 --> 00:00:21,810 into other sets of characters. 7 00:00:21,810 --> 00:00:25,980 And it is useful for converting uppercase into lowercase, 8 00:00:25,980 --> 00:00:28,260 or the other way around, 9 00:00:28,260 --> 00:00:31,620 or a completely different set of characters. 10 00:00:31,620 --> 00:00:34,050 You typically use it in a pipe. 11 00:00:34,050 --> 00:00:36,780 So, "echo hello", send it to a pipe. 12 00:00:36,780 --> 00:00:39,060 Then you do your tr stuff, 13 00:00:39,060 --> 00:00:41,070 by using either [:lower:] or [:upper:], 14 00:00:41,070 --> 00:00:45,600 or [a-Z] [A-Z], or even [a-m] [n-z]. 15 00:00:45,600 --> 00:00:46,653 Let me demonstrate. 16 00:00:49,230 --> 00:00:53,670 So I'm using echo hello | tr, 17 00:00:53,670 --> 00:00:56,897 followed by [:lower:] and [:upper:]. 18 00:01:03,510 --> 00:01:06,690 And that is translating the text that to receive 19 00:01:06,690 --> 00:01:09,150 from the pipe to uppercase. 20 00:01:09,150 --> 00:01:11,010 The structure of using [:lower:] and [:upper:], 21 00:01:11,010 --> 00:01:13,680 which basically is a regular expression, 22 00:01:13,680 --> 00:01:15,570 is really a nice structure 23 00:01:15,570 --> 00:01:18,900 because it works with many languages, 24 00:01:18,900 --> 00:01:22,090 including languages that have special characters 25 00:01:23,340 --> 00:01:27,420 that exist in languages like French, or German, or Spanish, 26 00:01:27,420 --> 00:01:31,345 like accents, and so, below or above, 27 00:01:31,345 --> 00:01:33,303 or around the character, and so on. 28 00:01:34,590 --> 00:01:37,250 So, let's get started with echo hello |. 29 00:01:40,244 --> 00:01:41,713 And |, that's to tr, 30 00:01:42,840 --> 00:01:46,517 and then I'm using [a-z] [A-Z]. 31 00:01:49,530 --> 00:01:50,363 There we go. 32 00:01:50,363 --> 00:01:53,070 This is translating "hello" into uppercase. 33 00:01:53,070 --> 00:01:56,910 Now that's all nice, but this [a-z] [A-Z] doesn't work 34 00:01:56,910 --> 00:01:58,773 unless it is a special accent, 35 00:01:59,700 --> 00:02:01,860 which occurs in many languages 36 00:02:01,860 --> 00:02:05,430 like Swedish, and German, and Spanish, and so on. 37 00:02:05,430 --> 00:02:10,430 If you are working with words in these languages, 38 00:02:10,800 --> 00:02:13,963 you might be better off using [:lower:] and [:upper:]. 39 00:02:13,963 --> 00:02:16,860 [:lower:] and [:upper:] is doing exactly the same 40 00:02:16,860 --> 00:02:19,320 as [a-z] and uppercase [A-Z], 41 00:02:19,320 --> 00:02:21,120 but it will deal the right way 42 00:02:21,120 --> 00:02:23,880 with letters that are containing accents. 43 00:02:23,880 --> 00:02:26,010 You can even do funny things with [A-Z]. 44 00:02:26,010 --> 00:02:28,057 What do you think of this one for instance? 45 00:02:28,057 --> 00:02:32,820 [a-m] followed by [n-z] 46 00:02:32,820 --> 00:02:36,237 is translating "hello" into "uryyo". 47 00:02:37,320 --> 00:02:39,540 Everything up from A up to M 48 00:02:39,540 --> 00:02:44,460 is translated in a matching character from N up to Z, 49 00:02:44,460 --> 00:02:48,150 and that's how you can use the tr utility. 50 00:02:48,150 --> 00:02:50,550 And in case you are wondering, why is that useful? 51 00:02:50,550 --> 00:02:54,150 Well, this is something that is useful in scripts, 52 00:02:54,150 --> 00:02:56,940 or any other environment where you need to make sure 53 00:02:56,940 --> 00:02:59,790 that your words have a certain case. 54 00:02:59,790 --> 00:03:02,043 Then, tr is a useful utility.