Operating System - OpenVMS
1752802 Members
4965 Online
108789 Solutions
New Discussion юеВ

Search a string in files

 
SOLVED
Go to solution
jess_14
Advisor

Search a string in files

Hi experts, I'm new in vms. Would like to search a specific string eg. abc in all the files.

Not sure whether there are commands available or we need to write a script for this.

Thanks in advance!
10 REPLIES 10
Steven Schweda
Honored Contributor

Re: Search a string in files

> [...] I'm new in vms. [...]

What are you old in?

> [...] all the files.

All _which_ files?

HELP SEARCH

For all the files at or below the current
default directory, something like:

search [...]*.* abc

For all the files on a particular disk,
something like:

search DISK:[000000...]*.* abc

As usual, many things are possible.
Deepa R Shenoy
Advisor

Re: Search a string in files

To search in the Current Directory, issue

$ set def DISK:[CUR_DIR]
$ search *.*;* "abc"

To search in the deep rooted directories present in the Current Directory, issue

$ search DISK:[CUR_DIR...]*.*;* "abc"

To search in all directories on a disk

$ search DISK:[000000...]*.*;* "abc"

For more information, have a look at Open VMS help for SEARCH.
P Muralidhar Kini
Honored Contributor
Solution

Re: Search a string in files

Hi Jess,

DCL SEARCH command is what you have to use.

$SEARCH "search-string"

Example:

1)$ SEARCH *.TXT "ABCD"

This searches all the "*.TXt" files in the current directory
for the string "ABCD".


2)$ SEARCH $DKA100:[USER]*.* "ABCD"

This searches all the files in the "$DKA100:[USER]" directory
for the string "ABCD".

You can also use the "/STAT" qualifier along with the search to
get some useful stats as number of matches, number of
lines/characters searched in files, time taken and so on.

Refer the DCL help on SEARCH for more details
i.e. $ HELP SEARCH

Regards
Murali
Let There Be Rock - AC/DC
Steven Schweda
Honored Contributor
jess_14
Advisor

Re: Search a string in files

Thanks for the reply! Definitely helps!
Hein van den Heuvel
Honored Contributor

Re: Search a string in files

Hello Murali,

You mentioned.. "You can also use the "/STAT" qualifier along with the search to get some useful stats as number of matches,"

Indeed. And when Jess becomes a little more advanced, He'll appreciated the SYSMBOLS that capture the statistics for further processing.

Personally I've recently started to ditch the full /STAT in favor of /LOG/WIN=0

I feel that this combo often tells me all I need to know: name, records, matches.

Regards,
Hein

P Muralidhar Kini
Honored Contributor

Re: Search a string in files

Hi Hein,

Yes, thats a good suggestion.

The "/LOG/WIN=0" will give you brief summary of Name, Record & Matches.
In most cases these information should be sufficient.

I do however use the window qualifer during searching for say some error message in a file. Because this not only gives the error message as output but also lists some code before the error message which would tell why the error is thrown and so on.

I did not use the "/LOG/WIN=0" combination before but would use it going forward.

Thanks N Regards,
Murali
Let There Be Rock - AC/DC
Don Nutt
Advisor

Re: Search a string in files

Hien,

That is very cool. I use /STAT to do reporting on log files.

I didn't think of using /WIN=0/LOG to provide a filter to serach for MATCHED / NOMATCH.

%SEARCH-S-NOMATCH
%SEARCH-S-MATCHED

PIPE sea *.log error /win=0/log | sea sys$input MATCHED

This provides a me a easy way to identify files quickly that need to be parsed for additonal info.

Thank you, you just made my day.


Don
John Gillings
Honored Contributor

Re: Search a string in files

Don,
If you're OpenVMS V8 or higher, SEARCH/STAT defines symbols, so there's no need to parse the output:

$ PIPE search/stat/nolog/noout login.com "$" >nl: 2>nl:
$ show sym search$*
SEARCH$CHARACTERS_SEARCHED = "1222"
SEARCH$FILES_SEARCHED = "1"
SEARCH$LINES_PRINTED = "0"
SEARCH$RECORDS_MATCHED = "46"
SEARCH$RECORDS_SEARCHED = "46"

I'm using PIPE for output redirection to throw away any output or errors from SEARCH. Since it's a single command, it's executed in the context of the current process.
A crucible of informative mistakes