Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using grep on a physical file

164 views
Skip to first unread message

Ewout

unread,
Jan 14, 2004, 5:16:20 AM1/14/04
to
I want to use grep to search for records in a physical file (not a
source physical file) that match a certain pattern. I have understood
that grep can only be used on source physical files, so I have a bit
of a problem. What's more: I only want to search in a specific field
of the record format. That is to say: in each record, I want to
evaluate only the positions x to y. Does anyone have a clue about how
to achieve this?

Thanks in advance for any suggestions.

Ewout

Steve Landess

unread,
Jan 14, 2004, 6:24:43 AM1/14/04
to


Why grep? You can use CPYF to search for a pattern in a
record in any type of physical or logical file.

Example:
I have a customer master file where the first name begins
in position 10 within the record.

CPYF FROMFILE(CUSMST) TOFILE(*PRINT) INCCHAR(*RCD 10 *EQ 'Stephen')
will find and print all records containing "Stephen" in this field.

CPYF FROMFILE(CUSMST) TOFILE(*PRINT)
INCCHAR(*RCD 10 *EQ X'E2A38597888595') does the same...(hex value of
"Stephen").

CPYF FROMFILE(CUSMST) TOFILE(*PRINT) INCREL((*IF CUFNAM *EQ 'Stephen'))
will do the same, but it uses a field comparison.

In all three cases, you can specify a file name as the TOFILE parameter,
and it will create a file and copy into the file the found records.
Example:
CPYF FROMFILE(CUSMST) TOFILE(QTEMP/CUSMSTXXX)
MBROPT(*REPLACE) CRTFILE(*YES) INCCHAR(*RCD 10 *EQ X'E2A38597888595')

Steve Landess
Austin, Texas
(512) 423-0935


Ewout Boter

unread,
Jan 14, 2004, 7:11:57 AM1/14/04
to
Steve,

I want to use regular expressions for the search pattern. I am afraid that
CPYF doesn't recognize these expressions.

Regards,

Ewout

"Steve Landess" <steve_...@hotmail.com> schreef in bericht
news:%F9Nb.1604$n8....@be1.texas.rr.com...
[...]

Qwerty

unread,
Jan 14, 2004, 7:53:20 AM1/14/04
to

"Steve Landess" <steve_...@hotmail.com> wrote in message
news:%F9Nb.1604$n8....@be1.texas.rr.com...

> Why grep? You can use CPYF to search for a pattern in a
> record in any type of physical or logical file.
What about speed? ( vs RPG for example)


Charles Wilt

unread,
Jan 14, 2004, 8:23:26 AM1/14/04
to
Regular expressions....

Well that shoots down SQL AFAIK, unless you only need '%' - any string,
or '_' - any single char.

I would suggest that your best best would be using Java or Perl. Both
offer regular expressions and are available on the iSeries. Java may be
a better bet, since it is built into the OS whereas Perl has been ported
and I've heard rumours of difficulty with it on OS/400.

http://java.sun.com/developer/technicalArticles/releases/1.4regex/
http://java.sun.com/docs/books/tutorial/extra/regex/

Also, REXX apparently has a similar functionality with it's parse()
function but it's a different syntax.


HTH,
Charles


In article <bu3bmb$2it$1...@news4.tilbu1.nb.home.nl>, ewout...@planet.nl
says...

Dan Hicks

unread,
Jan 18, 2004, 8:44:59 PM1/18/04
to
You should be able to use grep on a physical file, though I've never
tried. Find a Unix reference for grep to understand the syntax for
specifying specific columns to search. It may be helpful to define
a link to the file to simplify access, but you should be able to
refer to it using /QSYS/whatever/whatever.file.

Note that grep's abilities to search non-character fields are
limited, and that code page problems may confound things a bit.

There's really nothing special about a source PF vs a regular PF
except that the record format is predefined with line number and
date fields ahead of the text field.

--
Dan Hicks
Don't anthropomorphize computers. They don't like it.

Tim M

unread,
Jan 18, 2004, 10:57:23 PM1/18/04
to
As a general rule, you cannot use IFS interfaces such as QSHELL to access
database files. A database file is any file described using SQL or DDS.

Therefore, you cannot use grep to search through a physical file that has
fields defined.

"Dan Hicks" <danh...@ieee.org> wrote in message
news:400B369B...@ieee.org...

Dan Hicks

unread,
Jan 19, 2004, 10:01:48 PM1/19/04
to
Actually, a database file doesn't have to be described using SQL or DDS.

And I was given to understand that you COULD access a DB file from
IFS, though I've never tried it personally. I'll try to remember to
try it tomorrow.

--
Dan Hicks
If the wind will not serve, take to the oars. --Latin proverb

Tim M

unread,
Jan 19, 2004, 10:54:13 PM1/19/04
to
I did try it before I posted. And, indeed, you cannot use grep on a database
file.

My definition of database file was not intended to be exhaustive, merely
explanatory.

"Dan Hicks" <danh...@ieee.org> wrote in message

news:400C9A1C...@ieee.org...

Dale Berta

unread,
Jan 20, 2004, 9:52:53 PM1/20/04
to
You can name any traditional object through IFS. But operations you can
perform are severely limited.

For reference, traditional objects map to:
/QSYS.LIB/libname.LIB/objname.type
And file members map to:
/QSYS.LIB/libname.LIB/objname.FILE/mbrname.MBR
Where
"libname" is the library name (remember, every library has an object of
type *LIB in library QSYS)
"objname" is the object name
"type" is the object type, without the "*"
"mbrname" is the member name
Most database files have only one member, which is usually the same as the
file name. But database files can have multiple members. Source files are a
special type of database file.

Some examples...
LIBA/FILE1 *FILE is also known as /QSYS.LIB/LIBA.LIB/FILE1.FILE
Member LIBA/FILE2(FILE2) is also known as
/QSYS.LIB/LIBA.LIB/FILE2.FILE/FILE2.MBR
LIBA/I001 *PGM is also known as /QSYS.LIB/LIBA.LIB/I001.PGM

If you want to see these names, I suggest you use wildcards to limit the
number of names returned, unless you have a small library. If you wrklnk on
'/QSYS.LIB', you're in for a wait. This also applies to a share accessed
from a PC.

"Dan Hicks" <danh...@ieee.org> wrote in message

news:400C9A1C...@ieee.org...

Tim M

unread,
Jan 21, 2004, 12:16:46 AM1/21/04
to
As I stated in another post, you cannot use grep with database files. A
physical file is a database file if it has fields defined for it such as
those files created by SQL or with DDS or those duplicated from such files.

Source files and those physical files that were created with CRTPF xxxx
RCDLEN(nnn) can be accessed by grep

"Dale Berta" <da...@epix.net> wrote in message
news:9QlPb.10357$Bv6.3107444@news1.epix.net...

Dale Berta

unread,
Jan 21, 2004, 7:55:59 AM1/21/04
to
You're preaching to the choir. However, it appeared that Dan didn't know how
to access traditional names from IFS.

"Tim M" <scot...@cox.spammerssuck.net> wrote in message
news:5WnPb.26579$ii6.13154@okepread05...

Dan Hicks

unread,
Jan 21, 2004, 9:33:45 PM1/21/04
to
Tim M wrote:
> As I stated in another post, you cannot use grep with database files. A
> physical file is a database file if it has fields defined for it such as
> those files created by SQL or with DDS or those duplicated from such files.
>
> Source files and those physical files that were created with CRTPF xxxx
> RCDLEN(nnn) can be accessed by grep

Ah, there's the point of misunderstanding -- files created with
CRTPF RCDLEN **are** database files. They just have one field,
defined as all characters.

If you can't grep a file with multiple fields, you might get away
with grepping a logical that redefines the view to be one large
character field.

--
Dan Hicks
Do not let what you cannot do interfere with what you can do.
--John Wooden

Dan Hicks

unread,
Jan 21, 2004, 9:35:38 PM1/21/04
to
I definitely did know how to access database files from IFS. That's
why I figured grep would work. But apparently it only works for
files with a single character field.

--
Dan Hicks
Let him that would move the world, first move himself. --Socrates

Tim M

unread,
Jan 21, 2004, 11:10:05 PM1/21/04
to
I hate to belabor this but even a file with a single character field is not
eligible, the file *must* be a source file or a file created with the RCDLEN
parm specified.

Logical files are always ineligible.

"Dan Hicks" <danh...@ieee.org> wrote in message

news:400F368...@ieee.org...

0 new messages