Don,

Microsoft Powershell will add quotes around a comma delimited field.
However, it does it for all fields, not just Alphanumeric.

It's a free download.

This example command does the quote addition:
import-csv C:\Users\wayne\Documents\book2.csv | export-csv
C:\Users\wayne\Documents\book3.csv  -NoTypeInformation -Encoding UTF8

In REXX, you can parse out each field from your CSV and use the STRIP
function to take out the words that are numeric.
This file:
a,             1,       2, three
abc, 5, 3, def
hgi, 4, 6, ttt

Becomes:
"a","1","2","three"
"abc","5","3","def"
"hgi","4","6","ttt"

PARSE VALUE mystring with F1 ',' F2','  F3 ',' F4
F2 = STRIP(F2,,'"')
F4 = STRIP(F4,,'"')

OUTSTR = F1 F2 F3 F4

Having said all this, I'd just PARSE your original records and add the
quotes word by word where needed. They are in known positions, so you know
which ones to STRIP and rebuild.






On Thu, Mar 24, 2022 at 7:47 AM Don Johnson <
[email protected]> wrote:

> This is a post now to the listserv, instead of the Google group. Sorry for
> the duplication!
>
> Hi, I have a comma-delimited extract from a file that has numeric and
> character fields, and I would like to turn it into a true CSV file by
> making the character fields quoted.
>
> I have a 2-line header (column names, and column types) which indicates
> which are CHAR fields, but cannot figure out how to capture the information
> from the header to apply to the actual data lines.
>
> For example, I have this in my file:
> ITM_ID,DESC,SHORT_DESC,U_M,UNIT_PRICE,ON_HAND,COMMIT,INV_HOLD,DISC_QTY,DISC_PCT,B_O_QTY,ON_ORD,ACT_YR,ACT_MO,ACT_DAY
>
> CHAR(10) N.N.,CHAR(30) NOT NULL,CHAR(8) N.N.,CHAR(4) N.N.,DEC(7,2)
> N.N.,DEC(7,0) N.N.,DEC(7,0) N.N.,CHAR(1) N.N.,DEC(7,0) N.N.,DEC(3,1)
> N.N.,DEC(7,0) N.N.,DEC(7,0) N.N.,CHAR(2) N.N.,CHAR(2) N.N.,CHAR(2) N.N.
> A10000,CARPETED RUBBER
> MATS-FRONT-RED,FLOORMAT,PAIR,22.99,135,205,Y,5000,1.5,0,0,87,02,02
> A10001,CARPETED RUBBER
> MATS-REAR(RED),FLOORMAT,PAIR,12.99,277,14,N,250,1.5,0,0,86,02,20
> A10002,PERSONALIZED VINYL
> MATS(BEIGE),FLOORMAT,PAIR,19.99,296,7,N,250,1.5,0,0,87,02,03
> A10003,4-PIECE CARPET MAT SET (BLUE),MAT
> SET,SET,19.99,275,2,N,250,1.5,0,0,87,02,03
> A10004,SPLASH
> GUARDS-ALUMINUM,SPLSHGRD,PAIR,8.99,523,55,N,500,1.5,0,0,87,02,03
> A10005,SPLASH
> GUARDS-VINYL,SPLSHGRD,PAIR,8.99,550,25,N,500,1.5,0,0,87,02,03
> A10006,MONOGRAMMED SPLASH
> GUARDS,SPLSHGRD,PAIR,11.99,300,0,N,250,1.5,0,0,86,02,20
>
> and want the output to look like this:
> "A10000","CARPETED RUBBER
> MATS-FRONT-RED","FLOORMAT","PAIR",22.99,135,205,"Y",5000,1.5,0,0,87,02,02
> "A10001","CARPETED RUBBER
> MATS-REAR(RED)","FLOORMAT","PAIR",12.99,277,14,"N",250,1.5,0,0,86,02,20
> "A10002","PERSONALIZED VINYL
> MATS(BEIGE)","FLOORMAT","PAIR",19.99,296,7,"N",250,1.5,0,0,87,02,03
> "A10003","4-PIECE CARPET MAT SET (BLUE)","MAT
> SET","SET",19.99,275,2,"N",250,1.5,0,0,87,02,03
> "A10004","SPLASH
> GUARDS-ALUMINUM","SPLSHGRD","PAIR",8.99,523,55,"N",500,1.5,0,0,87,02,03
>
> "A10005","SPLASH
> GUARDS-VINYL","SPLSHGRD","PAIR",8.99,550,25,"N",500,1.5,0,0,87,02,03
>
> "A10006","MONOGRAMMED SPLASH
> GUARDS","SPLSHGRD","PAIR",11.99,300,0,"N",250,1.5,0,0,86,02,20
>
> Is there a way to see which column type contains CHAR( -- each of the
> types is column separated -- and then be able to apply quotes to that
> particular output field? I am not sure about this, but hope there is an
> answer here.
>
> Thank you for your help!
> Don Johnson
> Sr. Principal Support Engineer  |  MSD - Datacom product family
> Broadcom Software
>
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO IBM-MAIN
>


-- 
Wayne V. Bickerdike

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to