search and replace basics
Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators
search and replace basics
I have some key value pairs data where I need to extract certain elements from the data.
I have the following- ecda_ani=[ capture( longest 1 to 10 digits ) ] in my find field and I want to write all the digits to a new file with new field names. There will be a total of three fields in the new file so I will be search for mulitiple things in the find.
What is being returned is the equivalent of $0 (the whole string) instead of the captured data.
I have the following- ecda_ani=[ capture( longest 1 to 10 digits ) ] in my find field and I want to write all the digits to a new file with new field names. There will be a total of three fields in the new file so I will be search for mulitiple things in the find.
What is being returned is the equivalent of $0 (the whole string) instead of the captured data.
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: search and replace basics
Use $1, $2 etc to represent the captured fields in the replace field and change how they are formatted
Re: search and replace basics
I have tried a lot of different variations to extract two fields of data and nothing works. I must be missing something here.
Filter List
-----------
Filter options
| [ ] Log to file
| [X] Append to logfile
| Log filename: textpipe.log
| Threshold 500
|
|--Input from file(s)
| [ ] Confirm before processing each file
| [ ] Confirm before processing read/only files
| [ ] Delete input files after processing
| Process binary files
|
|--EasyPattern [["ecda_ani=",capture(longest 1 to 10 digits)]["ecda_Auth2Tier=",capture(letters)]] with [$1,"|",$2]
| [ ] Match case
| [ ] Whole words only
| [ ] Case sensitive replace
| [ ] Prompt on replace
| [ ] Skip prompt if identical
| [ ] First only
| [ ] Extract matches
| Maximum text buffer size 4096
|
+--Merge output to file C:\Documents and Settings\youngs\Desktop\test.txt
I want the output to look like this:
12345678|B
45387932|A
Filter List
-----------
Filter options
| [ ] Log to file
| [X] Append to logfile
| Log filename: textpipe.log
| Threshold 500
|
|--Input from file(s)
| [ ] Confirm before processing each file
| [ ] Confirm before processing read/only files
| [ ] Delete input files after processing
| Process binary files
|
|--EasyPattern [["ecda_ani=",capture(longest 1 to 10 digits)]["ecda_Auth2Tier=",capture(letters)]] with [$1,"|",$2]
| [ ] Match case
| [ ] Whole words only
| [ ] Case sensitive replace
| [ ] Prompt on replace
| [ ] Skip prompt if identical
| [ ] First only
| [ ] Extract matches
| Maximum text buffer size 4096
|
+--Merge output to file C:\Documents and Settings\youngs\Desktop\test.txt
I want the output to look like this:
12345678|B
45387932|A
Re: search and replace basics
This is absolutely maddening...I can get this to work but I clearly do not understand the logic behind the 'or' statement because the field "CallCenter" can be either xletters'-'sletters or just xletters. The or statement is treating the second variant as a separate variable which is not what I want to do.
Here is what I have. This captures the ecda_ani fine but it is not parsing the Call Center field correctly.
["CallCenter=",capture(longest 1 to 30 letters,'-',longest 1 to 2 letters) or
"CallCenter=",capture(longest 1 to 30 letters)
or
["ecda_ani=",capture(longest 1 to 10 digits)]
Here is what I have. This captures the ecda_ani fine but it is not parsing the Call Center field correctly.
["CallCenter=",capture(longest 1 to 30 letters,'-',longest 1 to 2 letters) or
"CallCenter=",capture(longest 1 to 30 letters)
or
["ecda_ani=",capture(longest 1 to 10 digits)]
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: search and replace basics
'Or' is not used in this way, and or and [] cannot be used in the replacement string.
Without seeing the source text, what you want is two patterns:
EasyPattern
Replace with
and
EasyPattern
Replace with
Then you need to use a Filters\Remove\Remove lines\Remove non-matching lines filter to remove lines that don't match this type e.g.
Note:If a part of the pattern does not match, it corresponding output variable $1-$4 will be empty.
Without seeing the source text, what you want is two patterns:
EasyPattern
Code: Select all
ecda_ani=[ capture(longest 1 to 10 digits) ]
Code: Select all
$1|B
EasyPattern
Code: Select all
ecda_Auth2Tier=[ capture(letters) ]
Code: Select all
$1|A
Code: Select all
[lineStart, 1+ not '|']|['A' or 'B']
Note:If a part of the pattern does not match, it corresponding output variable $1-$4 will be empty.
Re: search and replace basics
Here is what it looks like to the best of what I can put out.
PegQT=2,CallCenter=NConcord,ecda_ani=7038800000,PegPA=1,ecda_state=VA,ecda_hvc=HV00,OCS_Build_Version=1.05,RVQID=,ecda_DialedNum=866674xxx,CALLID=7BA3411AF339007AC0273C04
This is a lot harder than I thought...
PegQT=2,CallCenter=NConcord,ecda_ani=7038800000,PegPA=1,ecda_state=VA,ecda_hvc=HV00,OCS_Build_Version=1.05,RVQID=,ecda_DialedNum=866674xxx,CALLID=7BA3411AF339007AC0273C04
This is a lot harder than I thought...
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: search and replace basics
It's not hard when you know how...
What you've provided is even easier.
EasyPattern:
Replace with:
What you've provided is even easier.
EasyPattern:
Code: Select all
ecda_ani=[capture(longest 1 to 10 digits), 1+chars ]ecda_Auth2Tier=[ capture(letters) ]
Code: Select all
$1|A
$2|B
Re: search and replace basics
Can I put multiple search and replace into the same filter so that it processes the replace as $1|$2|$3 etc. How do you end and start a new one? With square brackets?
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: search and replace basics
You can, provided you match all the text in-between. You need to read the EasyPattern section in the help file.
Square brackets start a new EasyPattern section.
Square brackets start a new EasyPattern section.
Re: search and replace basics
I have read it too many times to count.....
- DataMystic Support
- Site Admin
- Posts: 2227
- Joined: Mon Jun 30, 2003 12:32 pm
- Location: Melbourne, Australia
- Contact:
Re: search and replace basics
Just replace each variable section of the original text with something of the form
e.g.
Of course, for some of these, 0+ is more appropriate than 1+ because they can be blank.
Also, 'digits' may need to be replaced by 'letters' or 'letter or digit'.
Code: Select all
[ capture( 1+ digits ) ]
Code: Select all
PegQT=[ capture( 1+ digits ) ],CallCenter=[ capture( 1+ digits ) ],ecda_ani=[ capture( 1+ digits ) ],PegPA=[ capture( 1+ digits ) ],ecda_state=[ capture( 1+ digits ) ],ecda_hvc=[ capture( 1+ digits ) ],OCS_Build_Version=[ capture( 1+ digits ) ],RVQID=[ capture( 1+ digits ) ],ecda_DialedNum=[ capture( 1+ digits ) ],CALLID=[ capture( 1+ digits ) ]
Also, 'digits' may need to be replaced by 'letters' or 'letter or digit'.
Re: search and replace basics
That example really helps. Thanks.