0

Below is the script I'm using

#!/bin/bash

export IFS=","

cat ddd.csv 

I need to get the contents of ddd.csv as an array. I also need to convert that array in the form of a table with headers.

Please help,I'm really new to unix shell.

6
  • 2
    Can you give us an example of the input, and exactly what you hope to do with it? Do you want an array where each item is one line of the CSV, or are you looking to read in multiple arrays, where each row from the CSV is returned as a single array? Or something else? Commented Jun 3, 2015 at 13:09
  • I need to compare the values of the mysql database with that of the csv array.How will i accomplish that? Commented Jun 3, 2015 at 13:16
  • Example of the input -> header1,header2,header3, content1, content2, content3, content1, content2, content3, content1, content2, content3 Commented Jun 3, 2015 at 13:19
  • 2
    When someone asks for additional information it is best to update your question rather than posting a comment (because the options for formatting things are much richer in the question). For example, your comment appears to show a single row, but from the names you have used I am guessing it actually represents multiple rows. Commented Jun 3, 2015 at 13:21
  • See stackoverflow.com/questions/22290809/… Commented Jun 3, 2015 at 13:30

1 Answer 1

1

This page shows some tricks on how to extract CSV data in bash as below:

#!/bin/bash
while IFS="," read f1 f2 f3
do
        echo $f1 $f2 $f3
done < ddd.csv

This should give you a table like output. Alternatively you can put the fields into an array or do whatever you like with them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.