 I've discussed a lot of the basic core utilities, the command line utilities on Linux, and today I wanted to continue along with that journey. Today I wanted to talk about the column command. Now column, as the name implies, what it does is it takes input and then spits it back out as output in a column format. So let me show you a few examples of what you can do with the column command. So let me open a terminal. So let me go ahead and make the terminal full screen, and I'm going to zoom way in here first. Let's check out the man page for column just to get a brief overview of what this is. You can see column. What does it do? It columnates lists, meaning you give it some input. It's going to spit it back out in a column kind of layout. Now what kind of flags and options are available? You have 15 to 20, I would guess, flags and options available. I'm going to show you a number of the more useful ones. If I scroll all the way to the bottom you can see the package that the column command is part of. It's actually part of the util-linux package. So it's not a GNU core util. It's also not a GNU find util. It's part of a group of packages that are part of the util-linux package, which I believe that particular group of packages is maintained and distributed by the Linux kernel team. You'll find a lot of useful command line utilities as part of the util-linux package. So I know fdisk and cfdisk are part of it. I believe the make file system command mkfs is also a part of that. MakeSwap, I believe, is also a part of it. I'm pretty sure the reverse command rev is also a part of that. If you're not familiar with the rev command it's pretty neat. If I do hello nerds, exclamation, and I pipe it into rev for reverse it spits it back out in reverse order character-wise. But the rev command is not the subject of today's video. So let's do something with columns. So I'm going to print f and I'll do column one space, column two, and then let's do a new line break, foo space, bar, and then another new line. If I just print that to standard output, you can see it's kind of in a column layout, right? Column one, column two. Of course they're different sized words so they don't really line up. This is just being printed to standard output how it would typically look. Now what happens if I feed it into the column command with no flags or options? Well it just takes the foo and the bar. It ignores those new line breaks, right? And it gives us column one, column two, foo, and bar in a column layout but they're all on one row. Now that is not exactly what I would expect from the column command. It does have a flag dash dash table for a tabled format. You can also just shorten that to a single dash t for table. And if I do that, now it prints the output exactly the way you would probably assume it should look. Column one, column two, and then foo and bar lined up exactly the right way. And of course instead of just feeding it some input here at the command line, you could give it a file name as input. Let's create a file. So let me do vim. I'll call this file one. Vim is not installed out of the box here in Ubuntu. So let me do sudo apt install vim. And now let me vim file one. And I'm just going to create some text here. So I'll do zero one space and then I'll give it a name. How about Alex and who is Alex space? I'm going to say he's the CEO of our company. Zero two can be Emily. Who is Emily? She is the vice president. And then I'll do zero three and Harry. He is going to be a board member. We'll do Patty. She was also going to be a board member. I should watch my spelling though. And then zero five. We'll do Tom. He is also a board member because I'm not that creative. All right. Now that we have this, I'm going to write and quit. And now let's do column on file one. And if I move my head out of the way here, and you can see again, because we didn't give it the tabled format, it didn't respect our columns. So let's go ahead and give it that dash t flag. I'm going to up arrow here in the bashell and column dash t for tabled format. And now it looks like we would expect, right? Well, almost. You see board and member was really just one field, but it broke it up into two different fields because by default, the column command breaks on spaces. So how do we get around that? Well, the only way to get around that is either to go back in our file and remove the space between board and member, maybe put a dash there, which kind of looks weird, or remove the spaces between the columns and add a specific field separator. And I think that's what I would do. So if I do them file one again, and I'm going to go back in here, let's get into visual block mode, I'm going to change all of those spaces to a pipe symbol. Let's make the pipe symbol our field separator, and then replace that with a pipe, and that with a pipe, that with a pipe, and that with a pipe, and we'll leave the spaces in the board member title. Now let's write and quit that. And if I up arrow back to the column command with the dash t flag for table now also give it the dash s flag for separator and specify that the pipe symbol is our separator. If I hit enter, now that is formatted very nicely. That's exactly the way we would expect that table to look. Now one of the more useful files on any GNU slash Linux system that you will find the column command extremely useful for is the slash at C slash pass WD file. So this is a file on every GNU slash Linux system. It contains all of your users on the system, all of their passwords, all of their default shells, all of their default home directories, yada, yada, yada. So if I cat the slash at C pass WD, you will see all of the users currently on this Ubuntu machine. And you can see it has seven fields. They're separated by colons. You can see that this is a bit of a mess to read. Wouldn't that be nice if it was in a tabled column kind of format? Well, we can actually do that. So let me clear the screen. So let me do column dash T for table slash at C slash pass WD. And you can see that is a bit of a mess because we've got a lot of stuff going on here. I've got to zoom back out for you guys to even see that I got to zoom way out because there's seven columns, some of the information and some of the columns is long. And that's why when it's trying to break all of this up, you've got line breaks in weird spaces because I did not give it a field separator. So that is something we definitely need to do on a file like this. So let's go ahead and give it a separator. The separator obviously needs to be a colon. And now let me zoom back out. That looks a lot better there. I scroll back up. That is a much cleaner way to read the pass WD file. Now let's talk about some of the other flags that you could use with the pass WD command. So you've got this tabled column to layout. Would you like a header at the top to actually label the individual columns? You can give the columns names. So if I up arrow back to this command here, and I go back and I throw in the dash capital N flag for let's name the columns and I'm going to name them one all caps comma two, three, four, five, six, seven. And if I hit enter on that, you can see we get the same tabled column layout. But now if I scroll all the way to the top, we have an extra row here where we have now named each column. You see one, two, three, four, five, six, and seven. Now when you have a lot of information here in the terminal, you see I had to zoom back out because it was so much information. The lines we're going to start breaking in weird places, you can actually tell the column command to truncate some of these columns. For example, I can already tell you the fifth column here, you know, some of these lines are kind of long, wouldn't it be nice to actually truncate that. So there is a truncate flag, I believe it is capital T. And then you specify the names of the columns. So if I just do column five slash etsy slash past WD and hit enter, nothing changed because it had room for all of the information because I'm full screen here. But let me make the terminal a little smaller here. So I'm going to make the terminal just a little smaller. I'm going to rerun that command. Let me move my head here. And again, we'll leave the dash T flag and the column that is named five. I want it truncated if it needs to be. And this time you see that there's no weird line breaks because that fifth column that had the unusually long descriptions. Sometimes now you can see those lines are truncated. You can see, for example, system D, capital U, I don't know where that was going, but I'm assuming there was more to that description there, but it cut it off because it needed to cut it off to fit all the lines in the space allowed for the size of the terminal as is. And of course, I could specify other columns to also truncate. So maybe I want to truncate lines five and seven, the last field, which is I believe the default shell for the user. And you can see now it gives more space to column five, but it truncated column seven cut off the shells. So that is how that would work. And if we wanted to play with one more flag again, dash O for the output field separator, so we could add something back in. So we took the input field separator as colons, and we could change the output field separator to a pipe symbol. And again, it will keep the tabled column so it's still lined up, but it throws a pipe symbol at the very beginning of the column. So actually that starts looking actually like a proper table. So that's just a little bit of what you can do with the column command again, part of the standard util Linux package. It's not a command you're going to use all the time, but sometimes when you're dealing with a specific kind of input that really belongs in a tabled kind of layout, you're going to appreciate the column command. Now before I go, I need to thank a few special people. I need to thank the producers of this show, Dustin Gabe James, Matt Maxim, Michael Mitchell, Paul West, Waiya Ball, Homie Allen, Armoredragon, Chuck Commander, Erie, Diokai, Dylan, Greg, Marstrum, Erion, Alexander, Peace, Archive, Adore, Polytech, Realiteats, for less red profit, Steven, Tool, Stevlar, and Willie. These guys, they're my high-steered patrons over on Patreon without these guys. This quick look at the column command would not have been possible. The show's also brought to you by each and every one of these fine ladies and gentlemen. All these names you're seeing on the screen right now, these are all my supporters over on Patreon because I don't have any corporate sponsors. It's just me and you guys until Joe's coffee calls and they want to sponsor me, I depend on you guys. Subscribe to DistroTube over on Patreon. Alright guys, peace.