Hi Monks. I have a comma delimited file. There are always values in fields 0-2 and always in 3 OR 4 but not both 3 AND 4. What I am trying to do is simply read each line and write it out as double-quoted comma delimited data, which I have accomplished. What I don't know how to do is not write out the empty field 3 or 4. Here is my code
open(INFILE1, "$ARGV[0]") or exit(101); open (OUTFILE1, ">" . "delimited_$ARGV[0]") or exit(201); $coid="$ARGV[1]"; if ("$coid" eq ""){$coid="***COID***";} while(<INFILE1>) { @file_line_contents = split (/\,/,$_); print OUTFILE1 "\"$coid\"\,\"".join ('","', @file_line_contents); }
For example, if I have this: AKP,45,MILITARY DIFF,,Exclude , I want to write out this: "***COID***","AKP","45","MILITARY DIFF","Exclude" (notice field 3 was not written out).
Is there a way to do this with a join command? If not, suggestions on how to best do it?
Thanks for any help.
In reply to Converting a delimited file. by insta.gator
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |