Extract Columns from file

Hi All,

Could you please help me with following:

I have to parse a .csv file.

For example: If the csv file contains 3 columns, then i have to print the column names. The field separator is (comma).

example.csv (contains 2 lines as follows)
This is,a test file, for validation purpose
This is,"""a test"", file","for validation "" pupose"""

I need the output like this:

1st line:
Input string: This is,a test file, for validation purpose
1st field:This is
2nd field:a test file
3rd field:for validation purpose

2nd line:
Input string: This is,"""a test"", file","for validation "" pupose"""
Actually from excel file, the data looks like this
(This is "a test", file for validation " pupose")
1st field:This is
2nd field:"a test", file
3rd field:for validation " pupose"

Thanks in advance for any tips.

Thanks,
Venkat

Hi,
I hope this how u want the output:

awk -F, '{print "1st field : "$1 " 2nd field : " $2 " 3rd field : " $3}' test.dat

---------- Post updated at 04:37 PM ---------- Previous update was at 04:32 PM ----------

May be this will give you the desired output as shown by you.

awk -F, '{print "Input string : " $0 "\n" "1srt field : "$1 "\n" "2field : " $2 "\n" "3rd field : " $3 "\n"}' test.dat
d02 $ cat test.dat
This is,a testfile,for validation
This is ," a test file","for validation puropse"""
d02 $
d02 $ awk -F, '{print "Input string : " $0 "\n" "1srt field : "$1 "\n" "2field : " $2 "\n" "3rd field : " $3 "\n"}>
Input string : This is,a testfile,for validation
1srt field : This is
2field : a testfile
3rd field : for validation

Input string : This is ," a test file","for validation puropse"""
1srt field : This is
2field : " a test file"
3rd field : "for validation puropse"""

H mac4rfree,

Thanks for replying. It is working....

If i have input in my csv file like this

This is," ""a"" test,"" file","for ""validation"" puropse"

Actually the above is 3 fields with value

1) This is
2) "a" test," file
3) for "validation" puropse

If data content contains comma, then csv encloses those fields with double quotes...also in cases..field itself contains double contains...

So, for the input
This is," ""a"" test,"" file","for ""validation"" puropse"

Output should be:
1) This is
2) "a" test," file
3) for "validation" puropse

I hope this example is clear. Please let me know if you need more clarity then i can provide you more details.

Thanks
Venkat