 Hello and welcome this video as part of a series be sure to check out previous videos or you might be lost But you know if you don't want to you don't have to just to review what we did in the previous video I told you to go ahead and check out this project I have up on get lab get lab.com forward slash millix 1000 forward slash documents for dash tutorials and to clone this repository in that Repository there are some shell scripts inside a subfolder which we're looking at and one of those scripts downloads this file Which is just some made up Data that I have that we're using we're gonna be pulling names from that or actually we've already pulled in for that So the first command we ran last time was the get people command Which is just W get command that pulls down that people CSV, which again, I'll show you right now Then we ran the command create Dot CSV and what that is generated a pretty good CSV that we can open the library office that has you know made up names and Fake salaries it generates some random numbers for gallery. So again Libre office, and we created a file called salaries dot CSV and it's comma comma as delimiters and then the string delimiters are quotation marks Because there are commas in the numbers and the quotation marks are just telling it, you know Don't split the columns up based on the commas in these fields because they're numbers So there that's great, and again, I can cap that out salaries But then if I want to grab some information from here like let's say I want to grep This Todd Copeland I could say, you know Grep for his line Give it a file that we're working with so there we go So I got his line and then let's say I want to grab, you know one of his salaries here I would normally try to use the cut command and say cut with a delimiter of a comma And I'd say field five, but there's problem because of the commas in the numbers And this is an issue. I'm sure that there are probably tools out there. They're designed for Maybe going through CSV files more efficiently parsing through them, but I'm not aware of them One option would be to convert this to a JSON file and using jq But here I'm going to try to use some tools that I'm used to using in this case cut So how can I use the cut command to actually cut one of these numbers? I mean, I could be like cut comma five six that would work, but that's that's kind of weird So what I want to do is actually want to convert this as I mentioned in the past Commas are the most common delimiters for these type of files, but you can use any character you want Tabs are common. In fact, these are CSV files, but you don't see them as TSV files for tab separated values, but you can use whatever character you want In fact, like I said when I opened it up in LibreOffice Salaries.csv here it's asking do I want to use tab? Do I want to use columns? Are they fixed with are they separated by semicolon spaces other where I can put in a number here, which is what we want to do so normally when I do My own csv files a common thing I'd use is a pipe symbol Because it's very uncommon when you're typing stuff So what I'm going to do is I'm going to change our delimiters into pipe symbols So what I'm going to do is I'm going to say said and I'm going to give the said the substitute commands. So this is saying Said substitute whatever between these first two forward slashes We were between the second two slashes G means globally do it more than once do it throughout the entire file in this file Right now we're just going to change the output. We're not going to actually Ma file file in fact I'm going to do one line of time so make it easier for you to read So I'm just going to cat out our salaries file into here And actually I'm going to I'll just let me go back up here. I'll just grep this line So again, I'm going to grep this line, but I'll pipe that into said just to make this easy for you to read And what I want to do is how do I know I want to change well We have those quotation marks. So if I say quotation comma quotation mark, I can change those to pipes So you can see here I changed all our delimiters at least between the numbers into pipe characters We have a few issues here. We have the comma between the name, which I'm not going to worry about I'm going to leave that as is and just have one column for the last name first name and have them separated by a comma Just as you would with the last name first first name last But you can see here that I have this comma quotation mark is beginning there So I'm just going to say here in said again. I'm going to run another said command only one of those And I'm gonna say to change the comma quotation mark And it is important that I do this in this order because if I did that before it would screw up our first pipe character But there now I have the name Then I have a pipe character, then I have number pipe character all the way down until the very end here we have a little quotation mark and Comma at the end there. So I'm just going to adjust that with the same thing I'm just gonna say instead of comma quotation I'll go to quotation comma again leaving this blank meaning in this case. I'm not going to add a pipe I could add a pipe there and we'll just add an extra column to the end of our CSV file Which is not unusual, but I'm just going to remove it. So there we go We have that so if I was to open up this file Then the usable Underscore csv.sh you can see that's all I do It's just one line of code other than echoing out what's happening I am going to take that file the salary file do exactly what we talked about the dash I is saying Change it in place. So we're actually going to modify the file this time So I'm just going to go ahead and run that command and It happens very very fast and now if I was to open up this File in LibreOffice same file as before but with modifications I can say not commas, but other and give it the pipe character and now I have a column with the names First name and last name all in the first column there and then 25 columns of the names are of the numbers And now I can use that cut command so I can say I can cat out Again, I'll just do that one line Right here, so I'm going to grab that one line But I can say cut with a delimiter of pipe Field five and I've got that salary and go the next year or the next year or the next year Because again these are made up salaries that we generated in the first video Anyway, that is making the file a little more usable for using the cut command again. There might be better options There might be tools out there. I know there's tools for parsing through JSON in your shell I haven't seen any that are for CSV because I think normally you would just use the cut command But depending on how your CSV file is formatted that may or may not be an option Obviously cut is just one option You could use Ock or said and you could probably get them to look at the the CSV file in certain ways But this is the simplest way was just convert those delimiters to pipe characters and then use cut to read through that So that's where we're at and we're going to continue moving forward this in future tutorials I do thank you for watching. Please visit films by Chris calm. That's Chris the cake. There's a link in the description as always I hope that you have a great day