search and replace basics

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

search and replace basics

Postby sheridany » Fri Jun 20, 2008 4:50 am

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.

User avatar
DataMystic Support
Site Admin
Posts: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: search and replace basics

Postby DataMystic Support » Tue Jun 24, 2008 11:08 pm

Use $1, $2 etc to represent the captured fields in the replace field and change how they are formatted
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

Re: search and replace basics

Postby sheridany » Fri Jun 27, 2008 3:17 am

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

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

Re: search and replace basics

Postby sheridany » Fri Jun 27, 2008 6:43 am

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

User avatar
DataMystic Support
Site Admin
Posts: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: search and replace basics

Postby DataMystic Support » Fri Jun 27, 2008 9:19 am

'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.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

Re: search and replace basics

Postby sheridany » Fri Jun 27, 2008 9:37 am

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

User avatar
DataMystic Support
Site Admin
Posts: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: search and replace basics

Postby DataMystic Support » Fri Jun 27, 2008 10:25 am

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
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

Re: search and replace basics

Postby sheridany » Tue Jul 01, 2008 9:26 am

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?

User avatar
DataMystic Support
Site Admin
Posts: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: search and replace basics

Postby DataMystic Support » Tue Jul 01, 2008 10:39 am

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.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

Re: search and replace basics

Postby sheridany » Wed Jul 02, 2008 9:11 am

I have read it too many times to count..... :oops:

User avatar
DataMystic Support
Site Admin
Posts: 2164
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: search and replace basics

Postby DataMystic Support » Wed Jul 02, 2008 1:06 pm

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'.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

sheridany
Posts: 39
Joined: Thu Nov 15, 2007 4:20 am

Re: search and replace basics

Postby sheridany » Thu Jul 03, 2008 4:53 am

That example really helps. Thanks.


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 6 guests