I have a Hex file which consists of around 3600 lines. Now I have a one-word 1000 in the file need to search that and read the exact above line of that text. For example:
1:2007200040040020A006000000050020A806000010050020B0060000101E0
2:2007400000020020C0060000EC010020C7060000F0010020CE060000F8010
3:04076000040200206F
4:20**1000**00B41200001810000015AB0110FDB301106DC00110FDAE011099B501
5:08102000000000002D0000009B
6:20102800B01200003C100000B1C00110A9BF011067C0011069B801
7:041048003000000074
Now in the above data 1000 is located at line number 4 and fetch Line number 3 data from that search operation.
I am using nodejs FS library.
Below is my code so far:
const parseTxt = async (csvFile) => {
const data = await fs.readFileAsync(csvFile);
const str = data.toString();
const lines = str.split('\r\n');
var total_lines = lines.length;
console.log('Total Lines', total_lines);
lines.map(line => {
if(!line) {return null}
result.push(Number(line))
});
lines.forEach(linebyline => {
var search1000 = linebyline.substring(3, 7);
if(search1000 == '1000'){
// Here I want to check line number of this search and also above line data as well as line number of that above line.
// Also want to Append "DOWNLOAD" text starting of this line data.
}
});
}
parseTxt('file.hex').then(() => {
// console.log(mergeSort({arr: result, count: 0}));
console.log('parseTxt===');
})
Thank you.