AS400 scan all files / libraries for string

Posted on 2008-11-17
Last Modified: 2013-12-06
In preparation for a softare upgrade, I need to search all files / libraries on my AS400 for a certain string.  This string could be contained in CL and / or RPG programs.  I used STRPDM  to scan and I got some results however, I could not scan the entire AS/400 as I need to (unless I am using the utility incorrectly?!)  I had to qualify a file and library before it could scan.  What is the best way to determine every instance where this string is found?
Question by:cosmit
    LVL 4

    Expert Comment

    This is a great website that I keep on hand just in case I have to find something on my iSeries.

    I hope this helps.

    Author Comment

    Thanks for the great reference material dude02.  Unfortunately, it did not help my current situation.  It is great material though.
    LVL 4

    Expert Comment

    You can use FNDSTRPDM command to search out strings.

    I hope this helps.

    Author Comment

    I tried the FNDSTRPDM command but it requires you to specify a file and a library list.  I want to search ALL files in ALL libraries so this won't do the trick.

    Any other suggestions?
    LVL 34

    Accepted Solution

    This is a bit tricky if you aren't used to Unix-style commands on the AS/400, but you can use the Qshell commands to do what you want.  Note that this requires that you have Qshell installed.  It is a free, optionally-installable component of the operating system.  Just type "QSH" at the command line to see if it is installed.  If it isn't, ask your sysadmin to install it for you.

    First, dump a list of all physical files in the system to an outfile.  You may not see files that you don't hae rights to, so you probably want to run this whole process under a profile with *ALLOBJ authority.  

    Note that this outfile will contain all data files and all source files in the system.

    DSPFD *ALL/*ALL *PF OUTFILE(mylib/allfiles)
    Then execute a Qshell command string similar to the following.  This can take a LONG time to run, depending on the number of members being searched, and you should probably run it in batch.  

    There are several ways to start a Qshell command:

    1) Interactively enter 'QSH" and press enter for a terminal-session style interactive session.
    2) Prompt the QSH command and enter the Qshell command string in the paramater provided.  This enables you to run Qshell commands from CL, for example.
    3) Use SBMJOB to execute the QSH command, containing a Qshell command string, in batch.

    db2 "SELECT '/QSYS.LIB/' || trim(MBLIB) || '.LIB/' || trim(MBFILE) || '.FILE/' || trim(MBNAME) || '.MBR' FROM mylib.allfiles WHERE mbseu2='CLP'" | xargs grep '172.' > /grep.txt  

    1) The "db2" command runs an SQL query over the "allfiles" table you created above, and creates a list of source members to search in IFS format (//QSYS.LIB/somelib.LIB/file.FILE/member.MBR).  This example just selects members with the Source Attribute set to CLP.  If you want to search other members, you will need to modify the query a bit.  Instead of listing all of the possible source member types, there is a file attribute that indicates if the file is a Data file or a Source file.  You could just use that in place of the mbseu2 clause.  I'm not on the corporate network right now so I can't get you the field name, but if you look at the fields in the "allfiles" file, you should see it.

    2) The "|" (pipe) symbol redirects this list of members into the "xargs" command.  Xargs allows you to take a list that is generated in one command and pass it to another command that cannot accept an arbitrarily-long list of parameters.

    3) "grep" searches each member for the given string, and the ">" symbol redirects the list of members where the string "172." is found to a file called "grep.txt" in the root of the IFS.

    Note that grep can take a regular expression, and has lots of options, so the search can be extremely complex.  Grep is a common Linux and Unix command, and you can find examples of search syntax at thousands of sites.  Search for "grep", "grep tutorial", and "regular expressions".

    You can find more information on the IBM Qshell environament and related Qshell commands at:

    - Gary Patterson

    Author Closing Comment

    Once again you came through -- Thanks!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Hello I read in a discussion about a person who configured a very simple mirror RAID with two hard drives; the system and data were on the same partition. He asked how to repair the system as it was not booting up anymore. In his case running …
    As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, ( because one time I did this and I essentially had a bricked …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now