• 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) 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

    Embedded SQL Exception/Error Handling Admin Alert: Elements Of An IBM i Incident Management Plan, Part 1

    Leave a ReplyCancel 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

  • More Power Systems Price Hikes, This Time They Are “Directional”
  • AI Is Not Just For Developers, It Is For Everyone At Your Company
  • Guru: Finding Data In The Forest – Exploring Three-Part Naming In SQL
  • Former IBMer’s New Book Puts The Midrange In The Spotlight
  • Have You Tried To Buy A Server Lately?
  • GenAI Is The Death Of Deterministic Project Budgeting
  • PTC Adds Support For VS Code With Implementer 12.7
  • Guru: Single Threading A Program Execution
  • As I See It: Push Back
  • IBM i PTF Guide, Volume 28, Number 21

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