Hi,
I have a txt file in this form:
Module:m1 path:pi1
Module:m2 path:po2
Module:m3 path:po3
Module:m4 path:pi4
and so on
I want to parse it and take only the part after “path” and only the ones with that contain po and then add a string to it, so each line should look like:
po2.addr
po3.addr
I’m reading the txt file using
while(!feof(file.txt))
fscanf(file,“%s”, line)
In reply to karin hallon:
Something like the code below will enable you to access the part after “path”
when I simulate this code I get the following output:
entry1=Module:m1
entry2=path:p1
module_name=m1
path_name=p1
Hope that helps…
===================
function string split_using_delimiter_fn(string str,string del);
string result;
for (int i = 0; i < str.len(); i=i+1) begin
if (str.getc(i) == del) begin
result = str.substr(i+1,str.len()-1);
return result;
end
end
endfunction
module file_parser();
initial begin
string entry1, entry2;
string hdr1, module_name, hdr2, path_name;
int fd;
fd= $fopen("Input.txt","r");
$fscanf(fd,"%0s %0s", entry1, entry2);
$display("entry1=%0s",entry1);
$display("entry2=%0s",entry2);
module_name = split_using_delimiter_fn(entry1, ":");
$display("module_name=%0s", module_name);
path_name = split_using_delimiter_fn(entry2, ":");
$display("path_name=%0s", path_name);
end
endmodule