Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing spaces and " from comma delimited file

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
Our server generating comma delimited cvs file from a database. The syntax of the file is somethig similar to:

ITEM #,DESCRIPTION,CASE PACK,UPC,ONHAND,ONODER,ONDEMAND,PRICE,CAT/CLASS,YTD SELLS
31888.16,ROYAL CREST 16PC GLASS DW ,2,85081593368,80,25000,2904,8.19,GAB2,51393.91
38270.16,"CONCORD HARVEST 16PC DW,GRAPE ",2,85081632746,4856,0,1704,8.77,GAB2,5542.26

What I need to do the following:

1. Remove heading row starting from ITEM # and ending YTD SELLS
2. Remove extra spaces Ex: . . .GRAPE . . . (some spaces after word GRAPE)
3. Remove "
4. Save Edited file

How can I do it? Any help would be appreciated.
 
The first is easy. Just don't write the first line out.

The second can be performed with something like:
Code:
$line_from_file = preg_replace ('/ ([\,"])/', $1, $line_from_file);

The third is not something you want to do. Those quotes surround a comma within a field. Take out the quotes, and that wil will have one more field in it than any other line. The workaround is to change the file from being comma-delimited file to being tab-delimited. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top