Hi Rick

*if* this guys data is really CSV, then by definition, the ',' is the
field delimiter. In order to allow ',' characters in the filed data, the
data can be enclosed in '"' characters. I don't think they are required
though in his data it sounds like all fields are enclosed in '"' chars.
Anyway, if the fieled is enclosed in '"' chars, you have to escape any '"'
characters in the data with another '"' like this '""'. 

So, I think better test data would be 

"Junk_1","Junk_2","Junk"_3","Junk_4"
"Junk""_5","""Junk_6""",",Junk_7,","Ju,""nk_8"

Which this script does not handle properly. I honestly don't know awk well
enough to fix it. :)

Gate, I think it's time you posted a few lines of sample data.

charles

On Tue, 18 Jan 2000, Rick L. Mantooth wrote:

> Bryan,
> Don't listen to those perl guys... ;-)
> See below
> 
> On Tue, 18 Jan 2000, Gate wrote:
> 
> => I need to do the following two things (separately):
> => 
> => First.. I have a file with comma delineated fields. The data in each field
> => is enclosed in double quotes ("). However, some data fields have a quote
> => within the quotes, and I need to remove that. What is my best choice for
> => this?
> 
> Ok,
> *Assuming* Some_File looks like this:
> 
> "Junk_1","Junk_2","Junk"_3","Junk_4"
> "Junk"_5","Junk_6","Junk_7","Junk_8"
> 
> Syntax without "points off"
> quotes.awk < Some_File > Some_New_File
> 
> #!/usr/bin/gawk -f
> # quotes.awk
> # Input Data was:
> # "Junk_1","Junk_2","Junk"_3","Junk_4"
> # "Junk"_5","Junk_6","Junk_7","Junk_8"
> BEGIN{
>   FS=","
> }
> {
>   for(x=1;x<=NF;x++){
>     if(! match("\"[a-zA-Z0-9].*\"",$x) >0){
>       gsub("^\"","",$x)
>       gsub("\"$","",$x)
>       gsub("\"","",$x)
>     }
>   }
>       gsub(" ","\",\"",$0)
>     printf "\"%s\"\n",$0
> }
> # end quotes.awk
> 
> => 
> => Second.. A text file that contains data within brackets in this format:
> => useless text here[first/last]and useless text here
> => 
> => I need to just take the data "first" and "last" and output it into another
> => file like this:
> => first:last
> => 
> 
> Syntax:
> cat Some_File | split.awk > Some_New_File
> (probably get "points off" for the cat...<grin>)
> 
> #!/usr/bin/gawk -f
> # split.awk
> BEGIN{
>   FS="["
> }
> {
>   gsub("\\\].*$","",$2)
>   split($2,fld,"/")
>   printf "%s:%s\n",fld[1],fld[2]
> }
> # end split.awk
> 
> => So whats the best idea for that? Any takers? :)
> => Thanks!
> => 
> =>    Bryan
> => 
> => 
> => -- 
> => To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
> => as the Subject.
> => 
> => 
> 
> If you need me to mark up the scripts with # comments
> email me offline and I'll send you the info.
> We don't want to teach these new dogs "old tricks".. heh,heh..
> 
> Also, Might want to join us on the [EMAIL PROTECTED] list.


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to