fhg
Volume 10, Number 24 -- June 30, 2010

Spaces, Braces, and Semicolons

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


Sponsored By
PRODATA COMPUTER SERVICES

DBU 9.0 Now Available!

Just when you thought DBU had it all, we've added MORE!

                                                                 New DBUSQL command
                                                                 Enhanced Audit Logging
                                                                 Execute DBUJRN in batch
                                                                 Supports DBCS for Chinese,
                                                                   Korean and Japanese
                                                                 Wizard-based DBU security set-up

And MORE!

Download today!
800.228.6318
www.DoDBU.com


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Erwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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


 
The Four Hundred
Top Concerns Survey Is Ready for IBM Eyes

Infor Commits Itself to Microsoft and Windows Technologies

Developing for IBM i: Why Does It Need To Be So Hard?

Mad Dog 21/21: Microclients: Thin Enough? Rich Enough?

IBM Tweaks More Rebate Deals to Cut Power7 Prices

Four Hundred Stuff
IdF, Logic Trends Fill a Gap in Microsoft Identity Software

ADC Austin Updates AJAX Generator for CA Plex

ASD Unveils BI Solution for Insurance Companies

nuBridges' Token Manager Gets Enterprise Upgrade

SafeData Gets Bought by Data Storage

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
May 29, 2010: Volume 12, Number 22

May 22, 2010: Volume 12, Number 21

May 15, 2010: Volume 12, Number 20

May 8, 2010: Volume 12, Number 19

May 1, 2010: Volume 12, Number 18

April 24, 2010: Volume 12, Number 17

TPM at The Register
Oracle refreshes Sun Xeon server lineup

CPU, GPU makers gussie up their wares for Hot Chips

Azul goes virtual with Java appliance

Nimbula puffs up 'cloud operating system'

Oracle uses Sun as springboard in Q4

Neon to take mainframe complaints to Europe

Red Hat turns the crank of KVM enterprise virt

IBM sued over failed virtual PC server projects

AMD muscles Nvidia with fanless GPU coprocessors

AMD's Opteron 4100s march into x64 price war

Red Hat revenues swell to $209.1m

Tilera to stuff 200 cores onto single chip

THIS ISSUE SPONSORED BY:

SEQUEL Software
ProData Computer Services
WorksRight Software


Printer Friendly Version


TABLE OF CONTENTS
Generic Database Access with .NET 2.0

Spaces, Braces, and Semicolons

Admin Alert: High Availability Eliminates Disaster Recovery. . . Right?

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2010 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement