 Okay, today we're going to be taking a CSV file, which is a plain text file. It's a comma separate file. So basically it's a spreadsheet using commas to separate fields. Think of it as a spreadsheet. As I said, you know, for those of you who don't know it like an Excel file, right? But it's plain text can open up in a text editor or your office, whether you use LibreOffice or Google Docs or Microsoft Office. This is plain text. All those can open up. So we're going to take that a CSV file and convert it into a SQLite database file. And then we'll look at taking a SQLite database file, taking the table and exporting it to a CSV file. So the first thing we need is a CSV file to convert over to a SQLite database table. And I could have started off with one on my computer already, but I'm going to generate one real quick. This is something I've gone over in previous videos, but I'd just like to show it again, because it's so useful. If you ever need to generate fake user data for projects, randomuser.me is a great website. I'm going to use WGet that says go to this website. It's saying get a hundred results. You can give whatever number you want. And then I'm going to say export it as a CSV file. And we're going to save it to a file, right where we're at as people.csv. I gave the full path their name, but I could have just given it the CSV file. So we're going to do that. And now I can cat out that file and show what's inside it. I can also use Vim as a text error to go into it. And you can see the first line is telling what each column is, whether it's gender or name title, name first, name last, location, street, number, that sort of stuff. But then each line after that is the random information that we generated. I can, if we want to view that a little bit different, I can use visit data, also shortcut it as VD. And I can give it that file name and it will display and I can go through it from columns and rows like that. And then of course you can use, as I said, LibreOffice to open up a file like that or whatever office software you use. Then I'll click okay here. And there we go. We have it as a spreadsheet if you prefer that view. So we have that file and what we want to do now is, well, not close our shell. Let's reopen that. We are going to take that and we are going to convert it to a SQLite database table. And here we go. First thing we need to do is, again, I'm in an empty folder besides the file we just created. I'm going to use SQLite 3 and give it a file name. You don't have to give it the .sqlite extension. Some people use DB. But I have found that some programs such as visit data, if you don't give it that SQLite extension, it doesn't recognize what file it is, where normally visit data would recognize it. So you either need to tell it it's a SQLite database or give it that extension. So just to make things easy, I'm going to give it that extension. But just know in general, extensions don't matter to most programs. So I'm going to say SQLite 3. I'm just going to call it people.sqlite. And there, now I need to set the mode. If I don't do this, it will import what I tell it to you but not properly. But I'm going to say mode.csv. Our mode is set to CSV. So next what we want to do, we want to .import the name of our file. So people.csv. And then I will say, let's create a table called people. That's it. We just created a table called people and it contains the information from that CSV file using that first line as each field name. So if I want to, I can check the field names by using this command. I can say progamma. I don't know how you say that. Table underscore info and then the name of the table and it will list what each field is. And by default, it's just going to import each one as a textile field rather than a char or an integer, which is fine by me. Some people might have issues with that depending on how big your database is. But for small things like this, it doesn't really matter. And then next we're going to, we'll just look at everything in that table. Say select all from people and it will list everything that's in there, which was what is in our CSV file. Great. Let's do it again. Let's go ahead and quit out of this. And I am going to generate a new CSV. I'm just going to overwrite the old one. So I just generated a hundred new names and user information dumped into that file. So again, I'm going to SQLite and use the same database file, but we're going to create a new table. So again, I'm going to say mode, oh, sorry, mode CSV. And I'm going to say dot import. And we're going to give it that same file name. So people dot CSV. And I'll just give it another table name. I'll just say table, people two. And that's it. So again, if I dot tables, it will list all the tables. We have people and people two. And again, I can select all from people two. And you can see that you have to do semi colon at the end there. I have another table. Let's do it one more time just so we have a couple of tables not exit. We're going to do, sorry, dot quit. And again, we're going to generate a hundred new names, dump it, overwrite the old file. And then I'm going to go SQLite three people that SQLite. And then again, I'm going to say mode CSV. And again, if you don't do mode CSV, it will import the text. But basically, all the text is I think like one item instead of individual rows and columns. So mode dot CSV. And then we'll say dot import, we're going to import the people dot CSV. And we'll call this one customers, right? Maybe this is a customer database. Boom. If we do select all from customers. I typed something wrong. Select all from not form from. There we go. So now we have three tables within this one database file dot quit out of that. Now we have those, let's say we want to export one of those back out to a CSV file. Well, we could again go into that database and we can run all these commands and it will dump it to the screen, but we want to dump it to a file. So let's actually quit out of that. And what I'm going to say is I'm going to say, let's look at this database, but we're going to give it some parameters. We're going to say dash header, which means take the first, make the first line of the output, the names of each column. And of course, we're going to say dash CSV because we want to export it as a CSV file. And from this point, we can give it our SQL command. So so select all from and we'll just do people. All right, our people table. Don't forget the semi colon at the end there. That's it. If we do that, it's dumping it to the screen. Perfect. Now if we just want to put it in a file, I can just say people export dot CSV. And again, I can open that up in whatever program I want. I'll just say we'll use visit data. And there we go. We have our CSV file. We'll quit out of that. Now that's great. But again, we have multiple tables. So let's say we want to write a script or at least in this case, we'll write two lines of code where we can actually list all our tables, select the table we want from that list, and then export it to a file. So what we'll do here is we'll do that same command if we were to export it, but instead of putting it, I'm sorry, not that same command just yet, a similar command, we're going to say SQLite three, the name of our file, and then instead of select all from people, we're just going to give it the command of dot tables. And when we do that, it's going to list our tables. We have customers, people, and people too. So maybe I can put this right into FCF because you know I love FCF, right? So we're going to do that, but it lists them all as one line. So what we need to do instead is pipe it before FCF into something that will take the spaces and make them new line characters. So here we're using a TR command. It's saying, okay, make each space a new line character, which isn't going to be quite right. We need to add one more thing, but I'm going to show you the output of this, right? So it outputted the information we want each table, but we have all these extra empty lines. Let's go ahead and just say after that, we're going to say sort unique. There's probably other ways to do this might be better, but we're going to sort them all, make sure there's no duplicates. So basically all those blank lines is going to become one blank line. So we're going to have one blank line, but that's okay, right? So we have our blank line, but we can choose our output and then it gives that as an output. So that's what we want. We're going to throw that into a variable called table, right? So wrap this in quotation marks and a dollar sign and parentheses saying, take the output of this command and put it into this variable table. And I can choose my table. We'll say people. And if I echo dollar sign table, it says people. If I run it again and I choose customers, if I echo table, it now says customers. So now we can take that variable and put that up into this command. So what I'm going to do here is I'm just going to say instead of people, I'm going to say table, I'm going to say output.csv, right? Or I can actually use the table name and that way I can create tables, CSV files based on the table name. Just make sure you're not going to overwrite something important. Always have backups, because in this case, I already have a CSV file called people. So if I choose the people table, it's going to override that. So yeah, we'll have that. And I actually just exported a customer CSV file. If I run our first command again here, I can select people two and then run that second command. And now if I list out my files, you can see that I have a people two.csv. I can cap that out. And that's it. We imported and export. It's pretty simple. I tried to go quick so that I don't waste your time. But at the same time, it's very simple. If you look in the link in the description of this video, I have notes on this. It's literally, if you look at it, we got one for generating the CSV file, then we got one, two, three, four, five, six, seven, eight, eight lines of doing everything, importing, exporting, converting, checking. So go ahead and check out the link in the description of the video, as well as my website, filmsbychris.com. That's Chris with the K. And there you, there's a support section if you could financially support me. That's great. If not, like, share, subscribe, comment below. I thank you for watching. As always, I hope that you have a great day. And I hope I see some of you on my Patreon pages, I'll link to that in the description as well. Have a great day.