HomeОбразованиеRelated VideosMore From: theurbanpenguin

BASH scripting lesson 10 working with CSV files

359 ratings | 55382 views
More videos like this online at http://www.theurbanpenguin.com We now have some more great fun and see how much we can use the shell for; creating reports easily from the command line against CSV files. The script should be quite easy to read now as we use a while loop to read in the CSV file. We change the file delimiter to be the comma and then we have the line that we read in broken up into the schema elements we need. A report then is easy with colours and search ability. This is very usable
Html code for embedding videos on your blog
Text Comments (21)
Joshua Belisle (21 days ago)
ahh "after / before", I was confused for a long time thinking they were opposite of "above / below"
Rachel D (6 months ago)
ur the best
theurbanpenguin (6 months ago)
Thank you
Sourav Goswami (11 months ago)
A slow bash + ruby CSV file generator based on your script... #!/bin/bash names=(Justin Andrew Mellina Cody Bob Sally Jack Jill James) lasts=(Brown Seaforth Spratt Bean Tuern) jobs=(Manager Director Operator Factory PA) loc=(Factory Home Main) function generate { rand_name="${names[$(ruby -e 'puts rand(0..8)')]}" rand_lst_name="${lasts[$(ruby -e 'puts rand(0..4)')]}" rand_jobs="${jobs[$(ruby -e 'puts rand(0..4)')]}" rand_loc="${loc[$(ruby -e 'puts rand(0..2)')]}" pin=$(ruby -e 'puts rand(1000000..9999999)') echo "$rand_name $rand_lst_name,$rand_jobs,$pin,$rand_loc" } for i in {1..50} ; do generate >> csv.csv ; done
rajashekar reddy (8 months ago)
If you intrest this is my what'sapp 9701394688 I'm from india
rajashekar reddy (8 months ago)
Hello can you take my challenge I've scripting problems can u slove it
Shantanu Deshpande (1 year ago)
I have standard set of code written in while read loop and reading from csv file, my first column is server name and I want to extract the output to text file, but each time new text file need creating matching on servername and reading line by line from .csv file, how to achieve this using conditions etc
Ali shan (2 years ago)
you are amazing sir very helpful videos thank you so much
gegenderte Bratwuarst (2 years ago)
Thank you very helpful
pbofilms (3 years ago)
terminal is telling me that parsecsv.sh command is not found...advice?
Desafios :D (8 months ago)
Nbjhhh bi
一郎 (1 year ago)
Put dot slash (./) before the command name.
Persona Charles (3 years ago)
+sn3akyp3te You have to create the file parsecsv.sh with a text editor like Vi(Vim).
Adam Basha (4 years ago)
Very simple and yet AwEsOmE tutorial.  Thanq
Starcom23 (5 years ago)
You are my hero. I dont get part about bringing back IFS, why you once assigned it to coma and then set it back to initial configuration?
Leroy Diocotlhe (4 years ago)
Quote " IFS defaults to whitespace , this variable determines how your shell recognizes fields, or word boundaries, when it interprets character strings." Unquote Since CSV works with commas, IFS needs to know this in order for your shell to separate the fields correctly whenever it reads the CSV. Setting it back is just good behaviour. :)
JIAN ZHAO (5 years ago)
The sinppets directory is a great idea. Definitely I will create some sinppets. Thanks.
Luke James (5 years ago)
Good video. Thanks.
Desafios :D (8 months ago)
Nv V
Uzbeko (5 years ago)
You are great :)
Salim Zaffar (5 years ago)
can you please tell me how can I vlookup for a particular column froma csv file

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.