# How to identify a special character in a line while reading a file & then post process it for further computation in systemverilog?

**URL:** <https://verificationacademy.com/forums/t/how-to-identify-a-special-character-in-a-line-while-reading-a-file-then-post-process-it-for-further-computation-in-systemverilog/39856>\
**Category:** SystemVerilog\
**Tags:** fileread, SystemVerilog, Address, systemverilogmultidimentional-arraya-memory, readmemh\
**Created:** [December 1, 2021, 6:55am UTC](https://verificationacademy.com/forums/t/how-to-identify-a-special-character-in-a-line-while-reading-a-file-then-post-process-it-for-further-computation-in-systemverilog/39856 "2021-12-01T06:55:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RMK](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/b5e925/32.png) [@RMK](https://verificationacademy.com/forums/u/RMK)\
**Post date:** [December 1, 2021, 6:55am UTC](https://verificationacademy.com/forums/t/how-to-identify-a-special-character-in-a-line-while-reading-a-file-then-post-process-it-for-further-computation-in-systemverilog/39856/1 "2021-12-01T06:55:19Z")

</div>

Following is a sample file that I have which has a combination of addresses and data on individual lines,

1. @0
2. 1A
3. 1B
4. @C
5. 2D  
…

I would like to understand if I can implement the following steps while reading the above file in systemverilog testbench or if there are alternatives to do this,  
A) Identify the lines with @ symbol & then identify the associated address value.  
B) Add the address value (Ex: C from @C) to a base address.  
C) Run a for() loop until the next address is hit while reading the file and then repeat A, B & C.

I am trying with $readmemh(), but stuck in step-A.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [December 1, 2021, 8:26am UTC](https://verificationacademy.com/forums/t/how-to-identify-a-special-character-in-a-line-while-reading-a-file-then-post-process-it-for-further-computation-in-systemverilog/39856/2 "2021-12-01T08:26:08Z")

</div>

_In reply to [RMK](https://verificationacademy.com/forums/t/how-to-identify-a-special-character-in-a-line-while-reading-a-file-then-post-process-it-for-further-computation-in-systemverilog/39856):_

You can use $fscanf to read each line into a string. You can check the first character of the string to see if it is a “@”. Then you can use $sscanf to convert the string from a hexadecimal to a binary representation.
