This is the format Layer name, layer number, data type, text type. some times there are more than 1 data type, in which case they are grouped using "".NPLUS,32,0, NW,41,0,1 NWER,51,"0,1,2",12
For the first line NPLUS is the layer name,32 is layer number and 0 is the data type. There is no text type for this line
For the second line NW is the layer name,41 is layer number and 0 is the data type and 1 is the text type,
For the last line NWER is the layer name, 51 is the layer number, 0,1,2 is the data type and 12 is the text type.
I want to check the fields and print the following.I have written a sample code, but I am not able to figure out how to split based on two delimiters and then get the required result. the last line also should have a semicolon, where as other lines should have a coma at the end only. Here is the sample code.NPLUS layernumber 32 datatype 0, NW layernumber 41 datatype 0 text 1, NWER layernumber 51 datatype 0 datatype 1 datatype 2 text 12;
Any help would be greatly appreciated.open(my $in, '<', 'Text_File.csv') or die "Cannot open Text_File.csv: $!"; open(my $out, '>', 'mask.spec') or die "Cannot open mask.spec: $!"; while (my $line = <$in>) { #my @fields = split (/(?<="),(?=")/, $line); my @fields = split(/,/, $line); if (@fields == 4) { printf {$out} "%s layernum %s datatype %s,%s", @fields; } elsif (@fields == 5) { printf {$out} "%s layernum %s datatype %s text %s,%s", @fields +; } }
In reply to splitting csv file and saving data by Ganesh Bharadwaj1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |