Home Sitemap

About the PSKB / Terms of Use

Installing and running a script

"REVIEW_DATE";"AUTHOR";"ISBN";"DISCOUNTED_PRICE" 1985/01/21;"Douglas Adams";0345391802;5.95 1990/01/12;"Douglas Hofstadter";0465026567;9.95 1998/07/15;"Timothy ""The Parser"" Campbell";0968411304;18.99 1999/12/03;"Richard Friedman";0060630353;5.95 2001/09/19;"Karen Armstrong";0345384563;9.95 2002/06/23;"David Jones";0198504691;9.95 2002/06/23;"Julian Jaynes";0618057072;12.50 2003/09/30;"Scott Adams";0740721909;4.95 2004/10/04;"Benjamin Radcliff";0804818088;4.95 2004/10/04;"Randel Helms";0879755725;4.50

;=============================================================================== ; ; Sample script to tidy up a CSV (Comma Separated Value) file ; ; This script is designed for use with the Parse-O-Matic Power Tool ; ;------------------------------------------------------------------------------- ; ; Input: A CSV file with the following characteristics: ; ; - The fields are separated by semicolons rather than commas. ; This is common practice in Europe and South America. ; ; - There may or may not be quotes around non-numeric fields. ; This is, unfortunately, common practice by those who do not ; know about the canonical format for CSV files. For example, ; the file might have quotes around obvious text (such as a ; person's name) but omit the quotes around a date. ; ; - We will assume that the input file could contain some null ; records (i.e. lines with no data). Many CSV files have one ; or more blank lines at the end, or at other odd places. ; ; - We do not know in advance how many fields will be in each ; record. ; ; Output: We replace the semicolons with commas, and put quotes around the ; fields that are not purely numeric. ; ;=============================================================================== ; Input ;------------------------------------------------------------------------------- TrimChar $Data 'B ' ; Remove spaces at the edges If $Data = '' Done ; Ignore null lines Record = SplitCSV $Data #13 ';' ; Parse out the CSV fields ;------------------------------------------------------------------------------- ; Output ;------------------------------------------------------------------------------- OutCSV '' 'Init' ; Start of CSV output record Begin Record <> '' ; Loop through the fields Field = Parse Record '' #13 'Cut Relaxed' ; Get the next field TestNum = Numeric Field 'Yes' ; See if it's numeric or not If TestNum = 'Y' OutCSV Field 'Unquoted' ; If numeric, don't use quotes Otherwise OutCSV Field 'Quoted' ; Text fields use quotes Again ; Look for another field OutCSV '' 'Done' ; Send CSV record to output


Parse-O-Matic Free, Basic, Business and Enterprise are data conversion tools that allow you to parse, convert, mine, import and export data files, reports, web capture, logs, legacy databases, text, CSV (comma separated; comma delimited), ASCII, EBCDIC, and almost any data format that you may have.

Copyright © 1986-2011 National Data Parsing Canada Corporation All rights reserved. Legal