Printing a alpha numberic with special characters in to file as string

I would like to print a force hirachical path where it is defined,into a file,using UVM
for example I have a define file soc_defines.h having a define as
`define M2Line_MEM SOC_top.u_ddi_top.u_core.u_sram_wrapper.GAIN_SRAM_GEN_BLK[2].u_sram_1472x32.M31G123

where I need to write to another using N2Line_MEM instead of using full path,the issue here is `define being compile time directive and $fwrite being run-time
I have a sample code used
$fwrite(file_handle,$sformatf(“force SOC_top.u_ddi_top.u_core.u_sram_wrapper.GAIN_SRAM_GEN_BLK[2].u_sram_1472x32.M31G123.mem_array[%0d] = 'hF \n”,err_addr)

In the sample code,i need to use `M2Line_MEM rather than full hierarchy of the define,but I see that define does not get expanded,please kindly assist …

In reply to RKCH:

You need anothet define coverts M2Line_MEM to a string token using token pasting operators "

`define STR(s) `"s`"
`define M2Line_MEM SOC_top.u_ddi_top.u_core.u_sram_wrapper.GAIN_SRAM_GEN_BLK[2].u_sram_1472x32.M31G123

$fwrite(file_handle,$sformatf("force %s.mem_array[%0d] = 'hF \n", `STR(`M2Line_MEM), err_addr)



In reply to dave_59:

Thanks Dave