csv

export query results into CSV file issue in SQL Server

Hello everyone, I am using SQL Server 2008 Enterprise. I want to export the query result into csv file from SQL Server Management Studio. The issue is, the default csv file is comma (',') separated for each result column in each exported row, and I want to make it '\t' separated since comma exists in some of the result column values. A...

How to export 'date lookalike' text columns to csv

Hello all, I have the .net code written to export data to a csv file. The problem is that one of the columns has data like 5-8-13 When I double click the .csv file in excel this column shows data as 5/8/2013 i.e. it is misinterpreted as a date column which is not what I want. Is there some escape character which I can use while exporti...

Make a multi-column table from a CSV file using PHP

Sorry if this is a bit long, but I want to be as detailed as possible. Basically, I'm trying to create a multi-column table from a CSV file using PHP. I would like the table cells to list vertically. For example, if I have a CSV file with the names: bill mike sarah steve kim dave Assuming I need 2 columns, I would like the table to...

Postgres csv import duplicate key error?

Hi, I am importing a CSV file to postgres. copy product from '/tmp/a.csv' DELIMITERS ',' CSV; ERROR: duplicate key value violates unique constraint "product_pkey" CONTEXT: COPY product, line 13: "1,abcd,100 pack" What is the best way to avoid this error.. Would I have to write a python script to handle this error.. ...

Search zip-codes fast with jQuery

I have a list of zip-codes that I need to search trough using jQuery. I have the zip-codes in a CSV file like this: 2407;ELVERUM 2425;TRYSIL 2427;TRYSIL 2446;ENGERDAL 2448;ENGERDAL The list is pretty big, over 4000 entries, zip-code and corresponding city. What the fastest way to search trough the list in the browser? JSON? If that...

Mysql only imports a single row from CSV

Development machine is a Mac. I'm having some trouble importing more than a single line from a CSV into Mysql. Here is my SQL statement: LOAD DATA LOCAL INFILE 'test.csv' INTO TABLE students FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (pita, dob, name, grd, asst, loc); It runs fine, but only one record is imported. Any idea whe...

How to create an array from a CSV file using PHP and the fgetcsv function

Can someone kindly provide a code to create an array from a CSV file using fgetcsv? I've used the following code to create an array from a simple CSV file, but it doesn't work right when one of my fields has multiple commas - such as addresses. $lines =file('CSV Address.csv'); foreach($lines as $data) { list($name[],$address[],$status...

replace white spaces with a comma in a txt file in linux

Hi all, I need to edit few txt files (an output from sar) and to convert them into csv files. therefore I need to change every white space (or maybe it's a tab between the numbers in the output) using sed or awk functions (an easy shell script in linux) can anyone help me? every command I used didn't change the file at all (I tried gsu...

parsing CSV files backwards

I have csv files with the following format: CSV FILE "a" , "b" , "c" , "d" hello, world , 1 , 2 , 3 1,2,3,4,5,6,7 , 2 , 456 , 87 h,1231232,3 , 3 , 45 , 44 The problem is that the first field has commas "," in it. I have no control over file generation, as that's the format I receive them i...

Sort a CSV file by last name with PHP

How would I sort the following CSV file using PHP? I would like to sort by last name. Do I use regex somehow to get the first letter in the last name? Any help is appreciated Here is an excerpt of my CSV file - with a ";" delimiter between names and addresses John C. Buckley, M.D.;123 Main Street, Bethesda MD 20816 Steven P. Wood;34...

How do I detect missing fields in a CSV file in a Pythonic way?

I'm trying to parse a CSV file using Python's csv module (specifically, the DictReader class). Is there a Pythonic way to detect empty or missing fields and throw an error? Here's a sample file using the following headers: NAME, LABEL, VALUE foo,bar,baz yes,no x,y,z When parsing, I'd like the second line to throw an error since it's...

How are nested dictionaries handled by DictWriter?

Using the CSV module in python, I was experimenting with the DictWriter class to convert dictionaries to rows in a csv. Is there any way to handle nested dictionaries? Specifically, I'm exporting Disqus comments that have a structure like this: { u'status': u'approved', u'forum': {u'id': u'', u'': u'', u'shortname': u'', u'name': u'',...

PHP: Formatting irregular CSV files into HTML tables

My client receives a set of CSV text files periodically, where the elements in each row follow a consistent order and format, but the commas that separate them are inconsistent. Sometimes one comma will separate two elements and other times it will be two or four commas, etc ... The PHP application I am writing attempts to do the follo...

Using LINQ to query a text file

I have a simple text file containing some CSV with the following structure: @Parent1_Field1, Parent1_Field2, Parent1_Field3 Child1_Field1, Child1_Field2 Child2_Field1, Child2_Field2 ...etc. @Parent2_Field1, Parent2_Field2, Parent2_Field3 Child1_Field1, Child1_Field2 Child2_Field1, Child2_Field2 ...etc. '@' indicates a parent object ...

Funny CSV format help

I've been given a large file with a funny CSV format to parse into a database. The separator character is a semicolon (;). If one of the fields contains a semicolon it is "escaped" by wrapping it in doublequotes, like this ";". I have been assured that there will never be two adjacent fields with trailing/ leading doublequotes, so this...

Which delimiter should be used for lists of values inside a CSV file?

I have a CSV file that has lists of values for some fields. They're stored in the database as HTML "ul" elements, but I want to convert them into something more spreadsheet-friendly. What should I use as my delimiter? I could use escaped commas, pipes, semicolons, or pretty much anything else. Is there some kind of de facto standard p...

remove value from comma separated values string

I have a csv string like this "1,2,3" and want to be able to remove a desired value from it. For example if I want to remove the value: 2, the output string should be the following: "1,3" I'm using the following code but seems to be ineffective. var values = selectedvalues.split(","); if (values.length > 0) { ...

What data generators?

I'm about to release a FOSS data generator that can generate random yet meaningful data in CSV format. Rather belatedly, I guess, I need to poll the state of the art for such products - because if there is a well known and useful existing tool, I can write my work off to experience. I am aware of of a couple of SQL Server specific tools,...

How to convert mysql table data to Excel or CSV format in CakePHP?

Hi, I want to convert my sql data to csv files while clicking on a button. The code fragments I found for sql to CSV conversion were in PHP, and I'm trying to convert it to CakePHP since I'm working in CakePHP. Here is the PHP code I'm tring to convert: $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($...

Easiest way to import CSV into SQl Server 2005

I have several files about 5k each of CSV data I need to import into SQL Server 2005. This used to be simple with DTS. I tried to use SSIS previously and it seemed to be about 10x as much effort and I eventually gave up. What would be the simplest way to import the csv data into sql server? Ideally, the tool or method would create th...