Find in Macros

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
JBL
Posts: 170
Joined: 2003-04-25 14:33:59

Find in Macros

Post by JBL »

Is it possible to use find in macros? If so, what is the syntax? If not, make that a feature request. In Classic, PowerFind in conjunction with macros allowed you to do some cool stuff.
cchapin
Posts: 424
Joined: 2004-02-25 18:28:40
Location: Nagoya, Japan

Post by cchapin »

I don't believe so, but you can use regular expressions in Perl macros to do much of what you could with Find in macros. (That's why I'm trying to teach myself Perl.)

To second your motion, I think it would be great to have Find built into the macro facility without the need for Perl -- especially once Find becomes sensitive to formatting.

--Craig
JBL
Posts: 170
Joined: 2003-04-25 14:33:59

Post by JBL »

cchapin wrote: -- especially once Find becomes sensitive to formatting.
Yes, although often what I was interested in was going the other way around (e.g., setting everything that matches a certain pattern to be red). I don't think you can do that with perl, although... is there some way of handing the results of a perl search back to a command macro?
cchapin
Posts: 424
Joined: 2004-02-25 18:28:40
Location: Nagoya, Japan

Post by cchapin »

I hope that someone more knowledgeable than I am can give you a more helpful answer. I don't know how to do what you want to do all in a macro without user intervention of some kind.

--Craig
User avatar
Darren
Posts: 6
Joined: 2004-09-30 08:58:16
Location: San Antonio

Example of find/replace in macro

Post by Darren »

Took me a few days to learn enough of Perl to do this but I've been programming since '77 in lots of languages (your mileage may vary).
Start with web pages to get free Perl manuals:
[/url]http://www.ebb.org/PickingUpPerl/pickingUpPerl.pdf[/url]
[/url]http://www.perldoc.com/perl5.8.4/pod/perl.html[/url]

The heart is in
$textfile =~ s/find/replace/g; #Switches all (the g) "find"s to "replace"s
but takes overhead and must be a Perl file (ends in .pl) in your macros folder (easiest). Also note that backslashes are necessary in more places than in PowerFind Pro (before forward slash and period) in order to work in code.

This example takes Bank of America web page transactions copied to a NWE 2.0.1 file and makes it tab delimited and sets the style to Simple (my style sheet name) including font, size, color and rulers. The style part works under code control better than choosing it from the palette where the rulers don't get applied.

#Nisus Macro Block
#source clipboard
#destination clipboard

#Before Execution
#Clipboard 1
#Select All
#Copy

#After Execution
#Paste
#Simple
#Clipboard 0
#End Nisus Macro Block
use warnings;
use strict;

my $textfile = undef;
read STDIN,$textfile,1000000;

$textfile =~ s/\n[^0-9\/]*([0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9])[^0-9\/\n]*\n\s*(.+)\s*\n[^\$0-9,.\n]*(\$[0-9]*,?[0-9]*\.[0-9][0-9])[^\$0-9,.\n]*\n[^\$0-9,.\n]*\n[^\$0-9,.\n]*(\$[0-9]*,?[0-9]*\.[0-9][0-9])[^\$0-9,.\n]*/\n$1\t$2\t$3\t\t$4/g; # Debit

$textfile =~ s/\n[^0-9\/]*([0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9])[^0-9\/\n]*\n\s*(Check.+)[\s|\n]*(.+)\s*\n[^\$0-9,.\n]*(\$[0-9]*,?[0-9]*\.[0-9][0-9])[^\$0-9,.\n]*\n[^\$0-9,.\n]*\n[^\$0-9,.\n]*(\$[0-9]*,?[0-9]*\.[0-9][0-9])[^\$0-9,.\n]*/\n$1\t$2$3\t$4\t\t$5/g; # Check

$textfile =~ s/\n[^0-9\/]*([0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9])[^0-9\/\n]*\n\s*(.+)\s*\n[^\$0-9,.\n]*\n[^\$0-9,.\n]*(\$[0-9]*,?[0-9]*\.[0-9][0-9])[^\$0-9,.\n]*\n[^\$0-9,.\n]*(\$[0-9]*,?[0-9]*\.[0-9][0-9])[^\$0-9,.\n]*/\n$1\t$2\t\t$3\t$4/g; # Credit

print $textfile;


And I need a job (San Antonio, Design Engineering/Programming)
Be seeing you
Darren
Progressive Proximity Principle
Post Reply