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

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

    Your IBM Power Cloud Strategy Should Start With “Why?”

    Moving IBM i to the cloud isn’t just an infrastructure decision.

    A hardware refresh, data center exit, IBM i skills gap, disaster recovery requirement, or broader cloud initiative can each lead to a very different architecture.

    At Lightedge, we start by understanding what you’re trying to accomplish. Then we look at the workload, application dependencies, resiliency requirements, operating model, and long-term strategy to determine where that workload belongs.

    Managed IBM Power cloud? IBM Power Virtual Server? DR in the cloud? A hybrid architecture connecting IBM Power with AWS or Azure?

    There isn’t one right answer for every IBM i environment.

    Start with the business requirement. Understand the workload. Then decide where it belongs.

    Explore IBM Power cloud, managed services, and hybrid solutions from Lightedge.

    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

    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

    Generic Database Access with .NET 2.0 Admin Alert: High Availability Eliminates Disaster Recovery. . . Right?

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

  • IBM i Delivers New Development Tooling With 2026 Fall Tech Refreshes
  • Big Blue Says AI Is Not Behind The Big Uptick In IBM i Security Alerts
  • Guru: Web Service With Pagination
  • The GenAI Revolution And Product Shortages Send IT Budgets Skyward
  • IBM i PTF Guide, Volume 28, Number 40
  • IBM i PTF Guide, Volume 28, Number 41
  • Bob Code Assistant Gets Better Understanding Of IBM i Applications
  • IBM i In The Cloud And The Case For Reversing Replication
  • Guru: From Hiking Boots To Long-Term Memory
  • Inside IBM’s New PowerHA Cloud Offering, Full System Manager

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