Hello,
I'm new TextPad user! I have a very large file to edit (600000 lines). I would like to do as following:
1- Find the line have this format:
ATTR Type="STRING" Key="Name" Value=
It's complete line is, because the data after "Value=" is difference from time to time
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
2- Copy a complete line and insert it right below the original line
3- Change the Key="Name" of the copied line to Key="ALT"
Is there the way to have a macro to complete this task? Please help!
I would like to show again my example of what i try to accomplish
Existing file:
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
Result after copy:
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
ATTR Type="STRING" Key="ALT" Value="1SA - 123.4567.890-00"
Thanks!
Copy line then change its value
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
Welcome.
You don't need a macro; you can do this with a single regular expression replacement.
Use "Posix" regular expression syntax:
You don't need a macro; you can do this with a single regular expression replacement.
Use "Posix" regular expression syntax:
Search | Replace... (<F8>):Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
Find what: (ATTR Type="STRING" Key=)"Name" (.*)\n
Replace with: \1"Name" \2\n\1"ALT" \2\n
[X] Regular expression
Replace All
WOW! That's work great! Thank you very much!
In additional, I would like to need help and please advise which will be best way to get the result as following.
Existing file:
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
Result after copy:
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
ATTR Type="STRING" Key="ALT" Value="ALT - 123.4567.890-00"
Please notice that I was set up the style in value as "1st group Space-Space 2nd group" ("1SA - 123.4567.890-00"), so is there the way to change the 1st group which will be some variable value but the format still not change (in the example 1SA) to ALT on the copy line?
Thanks,
In additional, I would like to need help and please advise which will be best way to get the result as following.
Existing file:
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
Result after copy:
ATTR Type="STRING" Key="Name" Value="1SA - 123.4567.890-00"
ATTR Type="STRING" Key="ALT" Value="ALT - 123.4567.890-00"
Please notice that I was set up the style in value as "1st group Space-Space 2nd group" ("1SA - 123.4567.890-00"), so is there the way to change the 1st group which will be some variable value but the format still not change (in the example 1SA) to ALT on the copy line?
Thanks,
JTran
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
If a subexpression of a regex is parenthesised, the text it matches is captured and can be used in the replacement. The parentheses are numbered from left to right by the position of their left parenthesis symbols. In the replacement expression, \1 represents what was captured by the first parenthesised expression, \2 represents what was captured by the second, and so on.Find what: (ATTR Type="STRING" Key=)"Name" Value="([^ ]+)(.*)"
Replace with: \1"Name" Value="\2\3"\n\1"ALT" Value="ALT\3"
[X] Regular expression
Replace All