• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Spaces, Braces, and Semicolons

    June 30, 2010 Hey, Ted

    My Qshell script would work perfectly if I could make it count correctly. It thinks I have more objects in library QGPL than I really do have. Can you help?

    –Hugo

    Today is a spectacular day to improve our Qshell skills, thus improving our Unix and Linux shell skills and beefing up our résumés.

    Here is Hugo’s Qshell command:

    find /qsys.lib/qgpl.lib/ -name '*' | wc -l
    

    The “find” utility produces a list of everything (-name ‘*’) in QGPL. The list is passed along to the “wc” utility, which counts the number of lines (-l) in the list. The problem is that the list contains not only one line for each object, but also a line for the library itself and a line for each database file member.

    Let’s try a different approach.

    system dsplib qgpl | 
    sed -n '/Number of objects . . . . . . . . . . . :/{ s///; p; q; }'
    

    The system utility runs the Display Library (DSPLIB) command, writing the output to the standard output device (stdout). To see what this output looks like, run the following command from a CL command line:

    DSPLIB LIB(QGPL) OUTPUT(*PRINT)
    

    You’ll see something like this:

    5722SS1 V5R4M0  060210                   Display Library
    Library . . . . . . . . . . . . . . . . :   QGPL
    Type  . . . . . . . . . . . . . . . . . :   PROD
    Number of objects . . . . . . . . . . . :            2
    Library ASP number  . . . . . . . . . . :       1
    Library ASP device  . . . . . . . . . . :   *SYSBAS
    Library ASP group   . . . . . . . . . . :   *SYSBAS
    Create authority  . . . . . . . . . . . :   *SYSVAL
    Text description  . . . . . . . . . . . :   General Purpose Library
      Object      Type      Attribute             Size  Description
      MYPGM       *PGM      CLP                  73728  My program 
      YOURPGM     *PGM      CLP                  73728  Your program
    

    The pipe (vertical bar) tells Qshell that the output of DSPLIB is to be used as input to the stream editor, sed. Sed reads the output of DSPLIB, one line at a time, looking for lines that contain the string Number of objects . . . . . . . . . . . : This search string is known as an address. Notice that the address is delimited by slashes.

    When sed finds a line that matches the address, it executes the command string that follows the address. And this gives me a chance to show you some nifty features of sed.

    What do I want sed to do? I want it to strip off the Number of objects . . . . . . . . . . . : string. I want it to write what’s left of the line to stdout. Then I want sed to quit, because it has found what I was looking for.

    Nifty feature number 1 is that I don’t have to specify a search string in the “s” (substitute) sed command. If I omit this argument, sed assumes I meant the search string. Therefore, the following two substitute commands are equivalent in this case.

    s/Number of objects . . . . . . . . . . . ://;
    s///;
    

    Both tell sed to replace Number of objects . . . . . . . . . . . : with nothing.

    Nifty feature number 2 is that I can make sed execute more than one command. Like all things Unix, it’s cryptic, but here’s how it’s done.

    • End each command with a semicolon.
    • Leave at least one blank after each semicolon.
    • Surround the entire command sequence with braces.

    To strip out the search string, write to stdout and quit, do like this:

    { s///; p; q; }'
    

    All that’s left is to use command substitution to load the number of objects into a variable. (That’s nifty feature number 3!)

    NbrOfObjects=$(system dsplib qgpl | sed -n '/Number of objects 
    . . . . . . . . . . . :/{ s///; p; q; }')
    

    I know Qshell is weird to those of us who are accustomed to an engineered operating system, but believe it or not, a lot of people on this planet live and breathe this kind of stuff.



                         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
    Rocket Software

    Unlock the full potential of your data with Rocket Software. Our scalable solutions deliver AI-driven insights, seamless integration, and advanced compliance tools to transform your business. Discover how you can simplify data management, boost efficiency, and drive informed decisions.

    Learn more today.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    ManageEngine:  Who says iSeries systems monitoring software has to be expensive?
    IBS:  Free e-book: The Six Margin Killers in Wholesale Distribution
    COMMON:  Join us at the Fall 2010 Conference & Expo, Oct. 4 - 6, in San Antonio, Texas

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    Heartland Bank Selects Outsourced i/OS Offering from Jack Henry IBM’s Evolving Power Systems Rollout

    Leave a Reply Cancel reply

Volume 10, Number 24 -- June 30, 2010
THIS ISSUE SPONSORED BY:

SEQUEL Software
ProData Computer Services
WorksRight Software

Table of Contents

  • Remove Trailing Blanks from Legacy Columns with the IBM OLE DB Providers
  • How Did I Do That?
  • Admin Alert: Six Things You May Not Know About i/OS Passwords
  • Generic Database Access with .NET 2.0
  • Spaces, Braces, and Semicolons
  • Admin Alert: High Availability Eliminates Disaster Recovery. . . Right?

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