1 00:00:06,630 --> 00:00:08,610 - In this video, we will talk about cut 2 00:00:08,610 --> 00:00:12,960 and sort, which are easy to use text manipulation utilities. 3 00:00:12,960 --> 00:00:14,220 To start with, there is cut, 4 00:00:14,220 --> 00:00:17,400 which you would use to filter out columns from text files. 5 00:00:17,400 --> 00:00:19,200 If you want to use it the right way, 6 00:00:19,200 --> 00:00:21,720 you do need to specify to the field the delimiter. 7 00:00:21,720 --> 00:00:23,555 In cut, that is -d. 8 00:00:23,555 --> 00:00:25,590 This -d is what you are going to use 9 00:00:25,590 --> 00:00:28,923 to specify how cut can recognize fields, 10 00:00:29,760 --> 00:00:32,400 and let's just have a look at two examples. 11 00:00:32,400 --> 00:00:36,450 The first example is cut -f 3, etc, passwd, 12 00:00:36,450 --> 00:00:41,450 then we have cut -d :-f 3, etc, passwd. 13 00:00:41,460 --> 00:00:42,303 Let me show you. 14 00:00:44,490 --> 00:00:49,490 So let's start with cut -f 3 on etc, passwd, 15 00:00:53,520 --> 00:00:54,360 and what do we see? 16 00:00:54,360 --> 00:00:56,460 Well, we don't see any fields at all. 17 00:00:56,460 --> 00:00:58,170 It just prints the entire contents. 18 00:00:58,170 --> 00:00:59,430 Why is that? 19 00:00:59,430 --> 00:01:03,060 That is because it has no idea how to recognize a field, 20 00:01:03,060 --> 00:01:08,060 and that is why we need to add the field's delimiter, - d :. 21 00:01:09,210 --> 00:01:12,090 The colon is the field delimiter in this configuration file, 22 00:01:12,090 --> 00:01:15,630 and if you specify -d :, then there we go. 23 00:01:15,630 --> 00:01:18,813 We print the third field from etc, passwd. 24 00:01:21,180 --> 00:01:24,270 Often used together with cut, there is sort. 25 00:01:24,270 --> 00:01:26,883 Sort will sort the result of the cut command. 26 00:01:27,900 --> 00:01:30,360 By default, it will do that in alphabetical order. 27 00:01:30,360 --> 00:01:33,000 If you don't want it, you can use -n. 28 00:01:33,000 --> 00:01:35,130 - n will sort in numeric order. 29 00:01:35,130 --> 00:01:38,280 Let's just compare the behavior of these two commands. 30 00:01:38,280 --> 00:01:40,440 First command is where we are using just sort. 31 00:01:40,440 --> 00:01:43,833 Second command, where we are sorting -n. 32 00:01:45,930 --> 00:01:48,540 So here, back to our previous command. 33 00:01:48,540 --> 00:01:50,970 First, if you pipe through sorts, then what do we see? 34 00:01:50,970 --> 00:01:53,250 Well, we see that this is how it is sorting. 35 00:01:53,250 --> 00:01:55,590 So first, all the items that start with a one, 36 00:01:55,590 --> 00:01:57,720 then all the items that start with a two. 37 00:01:57,720 --> 00:01:59,580 That's probably not what you want, 38 00:01:59,580 --> 00:02:01,950 and that is why you wanna do a numeric sort. 39 00:02:01,950 --> 00:02:06,003 So sort -n is sorting in a numeric way.