[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9152.0. "Pipeing into awk" by SANITY::LEMONS (And we thank you for your support.) Wed Mar 12 1997 22:09

    Hi
    
    Is there any special magic I need to use to pipe the output from a
    program into awk as its input?
    
    Thanks!
    tl
T.RTitleUserPersonal
Name
DateLines
9152.1SSDEVO::ROLLOWDr. File System's Home for Wayward Inodes.Wed Mar 12 1997 23:2610
	Input or program?

		program | awk 'awk-program'

	has always worked for me.  Now if you want the program to generate
	the awk program, that gets a bit more interesting:

		awk '`program`'

	this will work up to the maximum length of a command line.
9152.2SMURF::FENSTERYaacov Fenster - System Engineering, Troubleshooting and other mThu Mar 13 1997 06:355
    Or you could (in csh):
    
    ((program > /tmp/$$.awk); (awk -f /tmp/$$.awk); (rm -f /tmp/$$.awk)).
    This will get around command line limitations. (So it's a hack. This IS
    UNIX isn't it ?....)
9152.3SANITY::LEMONSAnd we thank you for your support.Thu Mar 13 1997 08:1931
    Thanks very much for the suggestions.  Here's what I'm trying to do:
    
    # Use NetWorker to print the names of the active
    # clone backup pools.
    nsradmin << EOF
    show name
    print type:NSR group; autostart:Enabled; pool type:Backup clone
    EOF > awk /name:/ {
    # Use awk to extract just the pool names
    beginning = index ($0, ":")
    str_length = length ($0)
    group_name = substr ($0, beginning+2, str_length-beginning-2)
    print group_name
    }
    # For each clone pool, find the list of groups that use that
    # clone pool
    #nsradmin << EOF
    #show name; machine type
    #print type:NSR client; group: {$1}
    #EOF
    #
    
    When I execute it, I get:
    
    # csh -x names
    Line overflow.
    
    Thoughts?
    
    Thanks!
    tl
9152.4try thisUSMV01::DOUCETTEUse your judgementThu Mar 13 1997 11:1719
	Some suggestions:

<    EOF > awk /name:/ {
	
	try a pipe vs redirect

    EOF | awk /name:/ {
          .
          .
    }

	also add some single quotes

    EOF | awk '/name:/ {
          .
          .
    }'

9152.5SANITY::LEMONSAnd we thank you for your support.Thu Mar 13 1997 11:5140
    Hi
    
    Thanks for the suggestions.  Here's what happened:
    
    >>EOF > awk /name:/ {
    
    NetWorker administration program.
    Portions Copyright M-) Digital Equipment Corporation 1996. All rights
    reserved.
    
    Restricted Rights: Use, duplication, or disclosure by the U.S.
    Government is subject to restrictions as set forth in subparagraph
    (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR
    52.227-14 Alt. III, as applicable.
    
    Portions of this software are proprietary to and embody the
    confidential
    technology of Digital Equipment Corporation.  Posession, use, or
    copying of this software and media is authorized only pursuant to a
    valid written license from Digital or an authorized sublicensor.
    
    Use the "help" command for help, "visual" for full-screen mode.
    nsradmin> nsradmin> No resources found for query:
                       autostart: Enabled;
                       pool type: Backup clone;
                            type: NSR group;
    nsradmin> unknown command: EOF
    
    >>EOF | awk /name:/ {
    
    Same as above
    
    >>    EOF | awk '/name:/ {
    
    Same as above
    
    Thanks again.  Maybe it's that method of using EOF to bound the
    nsradmin command . . .
    
    tl
9152.6Maybe you have to "quit"NETRIX::&quot;[email protected]&quot;Brian HaleyThu Mar 13 1997 13:3615
Hi,

You don't ever quit (or exit or...) nsradmin.  Maybe this would fix your
problem:

nsradmin << EOF
show name
print type:NSR group; autostart:Enabled; pool type:Backup clone
quit
EOF

Quit might not be the right command, but you understand what I'm saying.

-Brian
[Posted by WWW Notes gateway]
9152.7Commands go togetherQUARRY::reevesJon Reeves, UNIX compiler groupThu Mar 13 1997 16:038
You need to put the commands together.  In other words:

nsradmin << EOF | awk
[nsradmin commands]
EOF

It's going to make things *much* clearer if you split out your awk script
into a file and use the -f option.
9152.8SANITY::LEMONSAnd we thank you for your support.Thu Mar 13 1997 18:2922
    Jon
    
    Right on:
    
    nsradmin << EOF | awk '/name:/ {
    beginning = index ($0, ":")
    str_length = length ($0)
    group_name = substr ($0, beginning+2, str_length-beginning-2)
    print group_name
    }'
    show name
    print type:NSR pool; pool type:Backup clone; enabled:Yes
    quit
    EOF
    
    produces the expected output.  And yes, it will be much clearer if I
    put the awk commands into a separate file.  Seeing the awk commands
    before what they are to parse is really putting the cart before the
    horse.
    
    Many thanks for the help!
    tl
9152.9SANITY::LEMONSAnd we thank you for your support.Fri Mar 14 1997 13:2618
    Even better than what I had before is this:
    
    #!/bin/ksh
    # Use NetWorker to print the names of the active
    # clone backup pools.
    nsradmin << EOF | awk '/name:/,/;/'
    show name
    print type:NSR pool; pool type:Backup clone; enabled:Yes
    quit
    EOF
    
    Now, my next magical act is to put the output of this into an array,
    that command in a while or for loop can operate on.  Any suggestions on
    how to do that?  I've been staring at the ksh man page and the awk
    section in the manual, but it's, er, kinda light on details.
    
    Thanks very much!
    tl
9152.10This might be a good time to learn perl...QUARRY::reevesJon Reeves, UNIX compiler groupFri Mar 14 1997 15:230