Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to be able to edit sections of text in the following way.

I might have a section as seen below.

Example.

Instance=wall

{

    VisGroups=(32)
    MeshFile=wall.gmt CollTarget=False HATTarget=False 
}

I need to find the section I want based on the 'Instance' name in this case 'wall' and then change the script in line 4

I would like to change CollTarget and HatTarget to True,

A simple case of cut/paste if it's only once or twice, but it can be up to 500 times and the sections will be scattered throughout the text, some areas will have the same script ie CollTarget=False HATTarget=False which doesn't need editing. The file can be as long as 5000 lines similar to the EXAMPLE below

Instance=object350

{

    MeshFile=object350.gmt CollTarget=False HATTarget=False 

}

Instance=box056

{

    VisGroups=(32)
    MeshFile=box056.gmt CollTarget=False HATTarget=False 

}

Instance=wall01

{

    VisGroups=(32)
    MeshFile=wall.gmt CollTarget=True HATTarget=False 

}

Instance=track01

{

    MeshFile=track01.gmt CollTarget=True HATTarget=True
}

NOTE also that the lines aren't all the same amount between the parentheses


but on the following section I may not want to do this.

Instance=20road007

{

    VisGroups=(32)
    MeshFile=20road007.gmt CollTarget=False HATTarget=True Response=VEHICLE,TERRAIN 

}

such as Add/Paste an extra piece of script or even Delete a piece of script completely


Is this possible using a macro? Could I do something in Notepad++ ..... it has lots of commands? Do I need to write a 'BASIC' programme. I don't understand macro's and my programming is limited.

How would I do this? It would be such a time saver. I hope I have made myself clear.

Any help would be greatly appreciated. Thank You

share|improve this question
2  
Your question is vague. You give the tool you have (Notepad++) and samples of the text you want to edit, but you aren't clear on exactly what you're trying to accomplish. In order to automate a process, there has to be something true of the parts to be changed that is not true of the parts that must remain unchanged. What is this for your example? –  Dane Apr 15 at 21:01

1 Answer 1

I'm making a few assumptions, but it appears you want to find all lines that contain

MeshFile=<someValue>.gmt

then update the parameters for CollTarget and HATTarget to TRUE, without touching any of the other parameters that may be on that line.

Assuming that CollTarget and HATTarget are always the first two parameters, and in that same order, you can run a Replace All command (CTRL+H) on your file and user the following:

Find what =    (.*)(wall.gmt) CollTarget=(\w+) HATTarget=(\w+)(.*)
Replace with = $1$2 CollTarget=True HATTarget=True$5

Explanation:

  • See the Notepad++ Regex documentation for general syntax (http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Regular_Expressions)
  • Any value found by the pattern within parenthesis will be available in the "$N" syntax. The number cooresponds to the parenthesis pair count in the find expression.
  • Change the value in the second parenthesis pair to change the instance name that you want to do a replace/update for. In my example I used wall.gmt
  • The replacement expression can be translated to:
    • Insert anything found at the beginning of the line before the instance name - the stuff found by "(.*)"
    • Insert the instance name that was searched for (so you don't have to type it in the search and replace expression)
    • Give the new values to CollTarget and HATTarget
    • Append anything that was found after HATTarget

If my assumption that CollTarget and HATTarget are not always the first or in the same order, then you will need to modify the search expression into two separate search and replace calls where the first searches for only CollTarget and updates that parameter's value, then a second one to look for HATTarget and update it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.