Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

perl equivalent of DCL search command

 
SOLVED
Go to solution
Michael L. Mulhern
Occasional Visitor

perl equivalent of DCL search command

I am looking for a perl script that performs the same function as the DCL search command.

My company is switching from VAX to PC. The Windows search provides only the name of files containing the search string. I am VERY used to the DCL search feature of providing each line and the nearby lines (window) and would like to get the same capability on a PC.
5 REPLIES 5
Hein van den Heuvel
Honored Contributor
Solution

Re: perl equivalent of DCL search command


I have a '\perl\bin\search.bat' that I _think_ came with the ActiveState perl distribution.

It is a perl script and does roughly what you want. It starts with:
## search
##
## Jeffrey Friedl (jfriedl@omron.co.jp), Dec 1994.
## Copyright 19.... ah hell, just take it.
##
## BLURB:
## A combo of find and grep -- more or less do a 'grep' on a whole
## directory tree. Fast, with lots of options. Much more powerful than
## the simple "find ... | xargs grep ....". Has a full man page.
## Powerfully customizable.


Personally, I often stick to the one-liners:

$ perl -le "print for (1000..4000)" > tmp.txt
$ perl -ne "$i=3 if /456/; print if $i-- > 0; print qq(\n) unless $i" tmp.txt
1456
1457
1458

2456
2457
2458

3456
3457
3458

I have also create several search algoritmes with pre-match and post-match output in perl and awk.. but the OpenVMS SEARCH/WIN is the best!

Google for "hein perl search" :-)

One example for a searching with a window...
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=630972

It is not too hard to add a file widlcard, but typically goes beyond one-liners:

$ perl -e "while ($f=shift) { open F,qq(<$f); while () { print qq ($f $. $_) if /main/} close F}" *.c
:
gbh.c 380 main(int argc, char *argv[])
getpos.c 12 int main(int argc, char *argv[]) {
getrmi.c 14 main(int argc, char *argv[])
:


Enjoy!
Hein


Joseph Huber_1
Honored Contributor

Re: perl equivalent of DCL search command


Besides perl scripts, GNU grep or egrep will do
it as well with the -A,-B,-C,-NUM options.
Windows versions of these and other Unix utilities can be found at
http://unxutils.sourceforge.net/

Unix utilities are also part of the Cygwin suite for windows.

http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: perl equivalent of DCL search command

And the search script mentioned by Hein is contained in
ftp://ftp.cpan.org/pub/CPAN/authors/id/J/JF/JFRIEDL/jeffrey.perl.tar.gz
http://www.mpp.mpg.de/~huber
Hein van den Heuvel
Honored Contributor

Re: perl equivalent of DCL search command



A much tighter and much less readily understood rewrite of the wildcard search:

Old:

$ perl -e "while ($f=shift) { open F,qq(<$f); while () { print qq ($f $. $_) if /main/} close F}" *.c

New:

$ perl -ne "close ARGV if eof; print qq($ARGV $. $_) if /main/" *.c

:-)

Michael L. Mulhern
Occasional Visitor

Re: perl equivalent of DCL search command

I downloaded Hein's search.bat from CPAN by following the explicit location provided by Joseph. Many thanks!!!