I am reading a map file and writing the data in a column format to a text file. The code I wrote is below, but it does not do the work for me.
fo = open(filename, "r+")
fu = open("map.txt","w+")
for line in fo:
if (".data.g" in line):
fu.write(line)
print line,
fo.close()
fu.close()
#to remove unwanted data
f = open("map1.txt", "w+")
g = open("map.txt", "r+")
for line in g:
if((".data " in line) and (".bss" in line) and(".text" in line )):
break
else:
f.write(line)
f.write('\n')
f.close()
g.close()
The output expected is
2007c04c .data g_isr_array
2007c004 .data g_retry_count
2007c000 .data g_pkt_hist_wptr
The input map file is the format
.data 0x2007c000 0x0 G:/SJSUDev_V2/SJSU_Dev/projects/lpc1758_freertos_v2/_build/L4_IO/wireless/src/mesh.o
.data.g_pkt_hist_wptr
0x2007c000 0x4 G:/SJSUDev_V2/SJSU_Dev/projects/lpc1758_freertos_v2/_build/L4_IO/wireless/src/mesh.o
.data.g_retry_count
0x2007c004 0x1 G:/SJSUDev_V2/SJSU_Dev/projects/ lpc1758_freertos_v2/_build/L4_IO/wireless/src/mesh.o
.data.g_our_node_id
0x2007c005 0x1 G:/SJSUDev_V2/SJSU_Dev/projects/ lpc1758_freertos_v2/_build/L4_IO/wireless/src/mesh.o
.data 0x2007c006 0x0 G:/SJSUDev_V2/SJSU_Dev/projects/ lpc1758_freertos_v2/_build/L4_IO/wireless/src/nrf24L01Plus.o
.data 0x2007c006 0x0 G:/SJSUDev_V2/SJSU_Dev/projects/ lpc1758_freertos_v2/_build/L4_IO/wireless/src/wireless.o
.data 0x2007c006 0x0 G:/SJSUDev_V2/SJSU_Dev/projects/ lpc1758_freertos_v2/_build/L4_IO/src/gpio.o
.data 0x2007c006 0x0 G:/SJSUDev_V2/SJSU_Dev/projects/ lpc1758_freertos_v2/_build/L4_IO/src/io_source.o
I want to read only the global variable which starts with ".data.g" but the address is on the next line which my code is unable to read.