Can I run grep against a zOS dataset via Unix system services?
772
I have a search I'd like to run against a zOS dataset, and I know how to form the grep command. I have access to the machine via Unix system services, how to I address a dataset from that environment?
How big a data set are we talking about?
The Unix system services cp command can take data sets as a source, and a Unix file (or directory) as a target, so conceivably if the data set is small enough you can copy it into files and grep away to your heart's content.
As an alternative, if you can open your data set in ISPF on the z/OS machine you may want to consider using FINDRX (which gives ISPF basic regex capability) -- I've never used it myself though so I can't vouch for it working or not.
"Search for a pattern across all datasets (partitioned and sequential) matching one or more dataset patterns"
The syntax:
dgrep [-hinvd] [-C<num>] <pattern> [<dataset-pattern>]+
-h: syntax
-i: ignore case
-n: display line numbers
-v: print names of datasets being searched
-d: print debug messages
-C: display <num> lines of context around a match
Copy files to uss-filesystem and grep there as mentioned above;
works for me.
Create an external link
(~ /usr/sbin/mount -f host.quali.pda -O 'SYNC(120)' mountpoint)
and grep via that link; currently not
working for me because of rights-restrictions.
The cat-suggestion works well for a single file, but not for all pds-members (at least i was not able to make it work).
I came across this thread after banging my head against the wall for about an hour.
My expereince - as very much a newbie on Z/OS, MVS, etc - is that grep against a PD (or is it a PDS, or a DSN, who knows!) is that this cannot be done directly
So, let's say I have text in a location like this: MYUSERID.SOME.DATA(DATA1)
(let me just interject, I have no idea how to refer to such a data "thing", I think it's a "PD")
Now, if I try to grep against the PD, using what seems like reasonable syntax:
===>grep FindMe "//'MYUSERID.SOME.DATA(DATA1)'"
$ grep: FSUM6261 read error on file "//'MYUSERID.SOME.DATA(DATA1)'": EDC511
3I Bad file descriptor.
Some other UNIX utility functions do work, for example:
==>ls "//'MYUSERID.SOME.DATA(DATA1)'"
ls: FSUM6785 File or directory "//'MYUSERID.SOME.DATA(DATA1)'" is not found
AND - don't forget, the pipe is your friend, except it may not be the "|" character.
It might very be the "!" (exclamation point) character.
This is basically an exercise in "try it out" the way you would in a real OS/SHELL combination, linux/BASH for example, and when that doesn't work, come up with a workaround for this idiotic, archaic System.
No need to cp first. You can cat, tail, grep etc. The thing to remember is the special quoting and that the DSN is preceded by two slashes:
cat "//'s052WX.EO.REXX(MYREXXSOURCE)'" | grep parse
If you look in the UNIX command reference manual under the cp command there’s more info.
How big a data set are we talking about?
The Unix system services
cp
command can take data sets as a source, and a Unix file (or directory) as a target, so conceivably if the data set is small enough you can copy it into files andgrep
away to your heart's content.As an alternative, if you can open your data set in
ISPF
on the z/OS machine you may want to consider using FINDRX (which gives ISPF basic regex capability) -- I've never used it myself though so I can't vouch for it working or not.Nowadays you can use
dgrep
commandAs the manual says:
The syntax:
For example:
More applications and examples: here
As far as i know there are two options:
Copy files to uss-filesystem and
grep
there as mentioned above; works for me.Create an external link (
~ /usr/sbin/mount -f host.quali.pda -O 'SYNC(120)' mountpoint
) andgrep
via that link; currently not working for me because of rights-restrictions.The
cat
-suggestion works well for a single file, but not for all pds-members (at least i was not able to make it work).I came across this thread after banging my head against the wall for about an hour. My expereince - as very much a newbie on Z/OS, MVS, etc - is that grep against a PD (or is it a PDS, or a DSN, who knows!) is that this cannot be done directly
So, let's say I have text in a location like this: MYUSERID.SOME.DATA(DATA1) (let me just interject, I have no idea how to refer to such a data "thing", I think it's a "PD")
Now, if I try to grep against the PD, using what seems like reasonable syntax:
Some other UNIX utility functions do work, for example:
and
Others, rather unhelpfully, do not:
AND - don't forget, the pipe is your friend, except it may not be the "|" character. It might very be the "!" (exclamation point) character.
This is basically an exercise in "try it out" the way you would in a real OS/SHELL combination, linux/BASH for example, and when that doesn't work, come up with a workaround for this idiotic, archaic System.
So my solution to your exact question is: