It is currently Tue, 07 Dec 2021 02:42:09 GMT



 
Author Message
 Passing a string Varible from AWK to a sh Script
     Can someone tell me how to pass a string varible from AWK to the
shell.  The following is an example of a shell script I'm having
problems with:

Shell script:
--------------------------------------------------
#!/bin/sh

# Line #1.  This is the line I'm having problems with:
# processno=`ps -ef | awk '$8 ~ /'$1'/ {print $2}{'theline='print $0}' -`

# Line #2   This is the working line, but I can't get the parameter $0
#           into the shell program.
processno=`ps -ef | awk '$8 ~ /'$1'/ {print $2}' -`

echo "Looking for: "          $1
echo "The process number is: "$processno
echo "The line found is: "    $theline
--------------------------------------------------

     I would like for the shell script to have the full line that AWK
processes.
     Thanks in advance for any suggestions or comments.

                                -- Larry
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Larry James                                                lja...@apollo3.com
Apollo III Communications                           72667.3...@compuserve.com
Computer Consultant/Programmer                    716-685-1865-ext 550  Voice



 Tue, 11 Feb 1997 21:08:31 GMT   
 Passing a string Varible from AWK to a sh Script
:      Can someone tell me how to pass a string varible from AWK to the
: shell.  The following is an example of a shell script I'm having
: problems with:
:  
: Shell script:
: --------------------------------------------------
: #!/bin/sh

: # Line #1.  This is the line I'm having problems with:
: # processno=`ps -ef | awk '$8 ~ /'$1'/ {print $2}{'theline='print $0}' -`

: # Line #2   This is the working line, but I can't get the parameter $0
: #           into the shell program.
: processno=`ps -ef | awk '$8 ~ /'$1'/ {print $2}' -`

: echo "Looking for: "          $1
: echo "The process number is: "$processno
: echo "The line found is: "    $theline
: --------------------------------------------------

:      I would like for the shell script to have the full line that AWK
: processes.

        It seems to me that you are trying to do two completely dif-
     ferent things at the same time.  The awk program is powerful but
     it cannot do everything -- especially all at the same time. :-)

        Are you trying to do something like the following *two step*
     procedure?:

   theLine=`ps -ef | awk '$8 ~ /'$1'/ {print $0}'`
   processno=`echo $theLine| awk '$8 ~ /'$1'/ {print $2}{'theline='print $0}'`

        I hope this helps.  May you grok in fullness ...

Bill--

+ William A. (Bill) Parrette -- _/_/_/ _/_/_/ _/_/_/    _/_/ ---------------+
|    bill@[Zeus.]itdc.edu        _/     _/   _/   _/ _/    _/  Call for     |
|4000 Executive Pk. Dr., #310   _/     _/   _/   _/ _/      Onsite & Public |
|  Cincinnati, OH 45241-4007   _/     _/   _/   _/ _/   _/ Class Information|
+------- 800-752-5448 ----- _/_/_/   _/   _/_/_/    _/_/ -------------------+



 Sat, 15 Feb 1997 03:56:35 GMT   
 Passing a string Varible from AWK to a sh Script

%%     Can someone tell me how to pass a string varible from AWK to the
%% shell.  The following is an example of a shell script I'm having
%% problems with:
%%
%% Shell script:
%% --------------------------------------------------
%% #!/bin/sh
%%
%% # Line #1.  This is the line I'm having problems with:
%% # processno=`ps -ef | awk '$8 ~ /'$1'/ {print $2}{'theline='print $0}' -`
%%
%% # Line #2   This is the working line, but I can't get the parameter $0
%% #           into the shell program.
%% processno=`ps -ef | awk '$8 ~ /'$1'/ {print $2}' -`
%%
%% echo "Looking for: "          $1
%% echo "The process number is: "$processno
%% echo "The line found is: "    $theline

First I'll inflict a few comments:
  (i). Just because tar needs a filename of "-" when you pipe into it does
       not mean that awk goes; it doesn't.
 (ii). I'm curious as to what the -f option to ps does as I've not seen it
       on any system.
(iii). What do you want to happen if ps gives you more than one matching
       line? I've just taken the first one (this is what the head -1 is
       doing).
 (iv). As usual, life would be simpler if you used nawk or gawk. Perl {*filter*}s
       would no doubt claim that perl should be used; but as I'm not one of them
       I can't admonish you with this.

And now a solution; there may be better ones:

#!/bin/sh

pro=$1
set -- `ps e | awk '$8 ~ /'"$pro"'/ {printf $0}' | head -1`

pronum=$2
linenum="$*"
echo "Looking for: "$pro
echo "The process number is: "$pronum
echo "The line found is: "$linenum"<"

---

Andrew Mathas

Wisdom is the principal thing;
therefore get wisdom; and with
thy getting get understanding.
                 Proverbs iv, 7



 Fri, 14 Feb 1997 19:08:31 GMT   
 
   [ 3 post ] 

Similar Threads

1. how to pass string from Win 9x program to linux shell script

2. passing string variable from script to a calling c++ program

3. Passing values generated in awk/nawk back to script

4. awk processing in sh script

5. awk and sh variables in a shell script

6. awk and sh variables in a shell script

7. awk script to check occurrences of string


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software