Page 1 of 1

search and replace basics

Posted: Fri Jun 20, 2008 4:50 am
by sheridany
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.

Re: search and replace basics

Posted: Tue Jun 24, 2008 11:08 pm
by DataMystic Support
Use $1, $2 etc to represent the captured fields in the replace field and change how they are formatted

Re: search and replace basics

Posted: Fri Jun 27, 2008 3:17 am
by sheridany
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

Re: search and replace basics

Posted: Fri Jun 27, 2008 6:43 am
by sheridany
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)]

Re: search and replace basics

Posted: Fri Jun 27, 2008 9:19 am
by DataMystic Support
'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

Code: Select all

ecda_ani=[ capture(longest 1 to 10 digits) ]
Replace with

Code: Select all

$1|B
and

EasyPattern

Code: Select all

ecda_Auth2Tier=[ capture(letters) ]
Replace with

Code: Select all

$1|A
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.

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

Posted: Fri Jun 27, 2008 9:37 am
by sheridany
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... :D

Re: search and replace basics

Posted: Fri Jun 27, 2008 10:25 am
by DataMystic Support
It's not hard when you know how...

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) ]
Replace with:

Code: Select all

$1|A
$2|B

Re: search and replace basics

Posted: Tue Jul 01, 2008 9:26 am
by sheridany
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?

Re: search and replace basics

Posted: Tue Jul 01, 2008 10:39 am
by DataMystic Support
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.

Re: search and replace basics

Posted: Wed Jul 02, 2008 9:11 am
by sheridany
I have read it too many times to count..... :oops:

Re: search and replace basics

Posted: Wed Jul 02, 2008 1:06 pm
by DataMystic Support
Just replace each variable section of the original text with something of the form

Code: Select all

[ capture( 1+ digits ) ]
e.g.

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 ) ]
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'.

Re: search and replace basics

Posted: Thu Jul 03, 2008 4:53 am
by sheridany
That example really helps. Thanks.