• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Search Source Members For Two Or More Strings

    April 2, 2014 Hey, Ted

    I have used option 25 of the Work with Members Using PDM (WRKMBRPDM) for years to look for character strings in source physical file members. Is there a way to search for two or more strings at once?

    –T.

    It’s not possible with that option. You might want to use option -e of Qshell’s grep utility.

    Let’s say you want to find all instances of invnbr and invoicenumber in source physical file SRC in library TST. Here’s the command you would need to use:

    $
    grep -in -e 'invnbr
    >
    invoicenumber
    >
    '  /qsys.lib/tst.lib/src.file/*
    

    The first, third, and fifth lines are Qshell prompt characters (i.e., $ and >). The second, fourth, and sixth lines are the ones that you key.

    Notice the three switches.

    1. -i means the search is not case-sensitive
    2. -n means that the relative record number (not the value of the SRCSEQ field) is to be included in the output
    3. -e means that two or more search strings follow, separated from one another by a newline character (i.e., the Enter key)

    Qshell responds with a listing something like this one:

    /qsys.lib/tst.lib/src.file/CRT.MBR:6:  ( InvoiceNumber dec (5,0) not null,
    /qsys.lib/tst.lib/src.file/CRT.MBR:9:   primary key (InvoiceNumber));
    /qsys.lib/tst.lib/src.file/CRT.MBR:16:  ( InvoiceNumber dec (5,0) not null,
    /qsys.lib/tst.lib/src.file/CRT.MBR:21: primary key (InvoiceNumber, Line));
    /qsys.lib/tst.lib/src.file/PRTF.MBR:2:   A            INVNBR         5  0
    /qsys.lib/tst.lib/src.file/INV01R.MBR:37:  select Ln.InvNbr, Ln.Line,
    /qsys.lib/tst.lib/src.file/INV01R.MBR:44:         on Ln.InvNbr = Hdr.InvNbr
    /qsys.lib/tst.lib/src.file/INV01R.MBR:73:      PrtINVNBR   =  zInvoiceNbr;
    /qsys.lib/tst.lib/src.file/INV102.MBR:76:      PrtInvNbr = ZIn(x).InvoiceNbr;
    

    Each line of output breaks down so:

    • The name, in IFS format, of the member in which a string was found
    • The relative record number of the line within the member
    • The contents of the line

    To write the contents to an IFS file (e.g., matches.txt), add redirection to the end of the command.

    $
    grep -in -e 'invnbr
    >
    invoicenumber
    >
    '  /qsys.lib/tst.lib/src.file/* >matches.txt
    

    To write the results to a report, use the Rfile utility.

    $
    grep -in -e 'invnbr
    >
    invoicenumber
    >
    '  /qsys.lib/tst.lib/src.file/*   | Rfile -wQ qsysprt
    

    –Ted

    RELATED STORIES

    Looking for Strings in the IFS

    Getting Acquainted with Grep

    Using Grep to Search Source Physical Files



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Maxava

    Migrate IBM i with Confidence

    Tired of costly and risky migrations? Maxava Migrate Live minimizes disruption with seamless transitions. Upgrading to Power10 or cloud hosted system, Maxava has you covered!

    Learn More

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    BCD:  IBM i Webinar April 10: How Automating Spool File Distribution Reduces Costs
    LANSA:  Webinar: Preserving your IBM i investment. April 10, 12 pm CT/1 pm ET
    Maxava:  Live Webinar: 11 Steps to Comprehensive DR Planning for IBM i. April 3

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Two More Customer Wins for Vault400 Big Blue Talks About IBM i And PureSystems

    Leave a Reply Cancel reply

Volume 14, Number 8 -- April 2, 2014
THIS ISSUE SPONSORED BY:

CCSS
WorksRight Software
Valence Framework for IBM i

Table of Contents

  • Embedded SQL Exception/Error Handling
  • Search Source Members For Two Or More Strings
  • Admin Alert: Elements Of An IBM i Incident Management Plan, Part 1

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle