I am trying to find rows beginning with 158 and containing a -
The dash can be in different positions. Some rows may even contain more than one. The file contains rows that begin with codes other than 158 but do contain a dash. They should be ignored.
Once I find the row beginning with 158 and containing dashes, I want to delete the dashes.
I can get how to find the rows beginning with 158 but can't figure out the "and contains" part.
158AS1 00000300066.580
158AS5 00000400048.800
158AS59 00000200045.420
158AX3 00000100022.800
158CB-125U 00000900000.640
158CH-14XV 00000100007.860
158CH-303 00000300002.270
158CH-307 00000300002.930
find rows beginning with and containing at the same time
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 10
- Joined: Wed Mar 12, 2008 2:33 pm
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
-
- Posts: 10
- Joined: Wed Mar 12, 2008 2:33 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
ben_josephs' solution should be working for you. You may have copied a blank space after the \1 replacement. Make sure it is only replacing "\1" and not "\1 "
===============
Here is an alternative, longer, but does the same thing.
This will replace a single instance of a - anywhere on a line starting with 158.
You could do multiple passes to remove additional - characters.
Find what: (^158.*)-(.*)
Replace with: \1\2
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
===============
Here is an alternative, longer, but does the same thing.
This will replace a single instance of a - anywhere on a line starting with 158.
You could do multiple passes to remove additional - characters.
Find what: (^158.*)-(.*)
Replace with: \1\2
Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Hope this was helpful.............good luck,
Bob
Bob
-
- Posts: 10
- Joined: Wed Mar 12, 2008 2:33 pm
solution to find and replace question
thanks for the quick and helpful responses.
this was my final solution.
i used find # (to make sure the symbol did not already exist in my data)
i used your find (^158.*)-
i changed the replace to: \1# (regular exp on and using replace all)
i repeated the replace all until the program responded with a cannot find
i then used:
find what: #
replace with nothing (regular expression off).
i recorded a macro and have tried it on a number of files and it is working nicely.
again, thanks for the direction.
this was my final solution.
i used find # (to make sure the symbol did not already exist in my data)
i used your find (^158.*)-
i changed the replace to: \1# (regular exp on and using replace all)
i repeated the replace all until the program responded with a cannot find
i then used:
find what: #
replace with nothing (regular expression off).
i recorded a macro and have tried it on a number of files and it is working nicely.
again, thanks for the direction.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
-
- Posts: 10
- Joined: Wed Mar 12, 2008 2:33 pm
because i replaced the - with a # only on the lines that began with the codes i needed, i was then able to just use find and delete all once it had done the change.
i could not get the \1 not to leave a space. i am new to textpad so maybe i will figure it out eventually but i was running out of time so just used a quick way around it.
hey - it worked and that's what mattered.
thanks for pointing me in the right direction. it was your find logic that let me get going.
i could not get the \1 not to leave a space. i am new to textpad so maybe i will figure it out eventually but i was running out of time so just used a quick way around it.
hey - it worked and that's what mattered.
thanks for pointing me in the right direction. it was your find logic that let me get going.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Good luck.
As you said, it is working for you, and that is the most important issue.
But when you get a chance, make the time to go back and look at the single step RegEx solution(s), do an autopsy to understand what is happening, and you will soon be on your own.
As you said, it is working for you, and that is the most important issue.
But when you get a chance, make the time to go back and look at the single step RegEx solution(s), do an autopsy to understand what is happening, and you will soon be on your own.
Hope this was helpful.............good luck,
Bob
Bob