• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. Edit a Text File and Replace a string

Stats

  • Replies 1
  • Subscribers 161
  • Views 13283
  • Members are here 0
More Content

Edit a Text File and Replace a string

vramananx
vramananx over 13 years ago

Hi

I want to open a text file and replace a particular pattern with another

I know i can use the regex to do the search and replace

i also know how to open the file

the thing i am not able to figure out is, how to read the entire text file

I am thinking I can read one line at a time and do regex for each line, then I can write the result to a new file

I need help in how to do this

 here is what I want to do

in = inport("file.txt")

lineread one line at a time assign to a string

use regex replace

fprintf the result to a new file

I also appreciate if anyone can suggest a better method

regards

Venkata

  • Sign in to reply
  • Cancel
  • SkilSiao
    SkilSiao over 13 years ago

    Hi Venkata, if i interprete correctly, you want to do a "read" of the entire text file first

    then followed by a "replace"?

    you may store each line of the input (from the file, as string)

    to a temp_list first, then compile the rex (or others required by your function),

    and then make a foreach loop to do the replacement.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information