awk question

awk question

Post by Yok » Sat, 28 Dec 2002 19:10:04



Hi,
I need help on this one. I'm new in shell scripting, my question is how can
I manage this with awk?
Tnx

**********
read $INPUT_FILE line by line untill EOF
put every line in temporary file (/tmp/temp.exe)
while a>b
    sleep
end while
# execute temp file
. /tmp/temp.exe
# that's all volks!!!
**********

Zok

 
 
 

awk question

Post by John » Sat, 28 Dec 2002 19:56:06



> Hi,
> I need help on this one. I'm new in shell scripting, my question is how can
> I manage this with awk?

There is a comp.lang.awk newsgroup.
Though whether you need awk really depends on what a and b are (below).

Quote:> **********
> read $INPUT_FILE line by line untill EOF
> put every line in temporary file (/tmp/temp.exe)
> while a>b
>     sleep
> end while
> # execute temp file
> . /tmp/temp.exe
> # that's all volks!!!
> **********

What are a and b?

If /tmp/temp.exe is just a copy of $INPUT_FILE, then
why not just execute $INPUT_FILE ?

And what do you really mean by "execute" since you
appear to be "sourcing" (with the dot) /tmp/temp.exe
rather than running it? Do you want to run it?

John.

 
 
 

awk question

Post by Yok » Sat, 28 Dec 2002 20:33:27


John, tnx for answer,
I didn't want to get into details, but here it is
a is a number, let's say 5
b is number of  oracle imp processess (so I got to assign something like
b=`ps -ef |grep imp|wc -l`)
/tmp/temp exe is not copy of $INPUT_FILE, it contains only one line (line by
line), and yes I want to run it (as far as I now dot means that I want to
execute file in current shell)
I think awk is the right tool, but any other way is also welcome

Z





Quote:> > Hi,
> > I need help on this one. I'm new in shell scripting, my question is how
can
> > I manage this with awk?

> There is a comp.lang.awk newsgroup.
> Though whether you need awk really depends on what a and b are (below).

> > **********
> > read $INPUT_FILE line by line untill EOF
> > put every line in temporary file (/tmp/temp.exe)
> > while a>b
> >     sleep
> > end while
> > # execute temp file
> > . /tmp/temp.exe
> > # that's all volks!!!
> > **********

> What are a and b?

> If /tmp/temp.exe is just a copy of $INPUT_FILE, then
> why not just execute $INPUT_FILE ?

> And what do you really mean by "execute" since you
> appear to be "sourcing" (with the dot) /tmp/temp.exe
> rather than running it? Do you want to run it?

> John.

 
 
 

awk question

Post by Juergen Hec » Sat, 28 Dec 2002 21:53:56



> John, tnx for answer,
> I didn't want to get into details, but here it is
> a is a number, let's say 5
> b is number of  oracle imp processess (so I got to assign something like
> b=`ps -ef |grep imp|wc -l`)
> /tmp/temp exe is not copy of $INPUT_FILE, it contains only one line (line by
> line), and yes I want to run it (as far as I now dot means that I want to
> execute file in current shell)
> I think awk is the right tool, but any other way is also welcome

[ snip]

This description is different from the pseudocode in your original post.
So i can only assume what you might want to do:

#! /bin/ksh
INPUTFILE=/path/to/inputfile  #adjust
a=5

while read -r cmd ; do
   while [ "$a" -gt `ps -ef |grep -c [i]mp` ] ; do
      sleep 2    ## adjust
   done
   eval $cmd
done <$INPUT_FILE

Regards
Juergen

 
 
 

awk question

Post by Yok » Sat, 28 Dec 2002 22:20:15


Tnx Juergen, that's the code I want and you asumed everything write, I tried
it, it works, tnx again!

Z


> > John, tnx for answer,
> > I didn't want to get into details, but here it is
> > a is a number, let's say 5
> > b is number of  oracle imp processess (so I got to assign something like
> > b=`ps -ef |grep imp|wc -l`)
> > /tmp/temp exe is not copy of $INPUT_FILE, it contains only one line
(line by
> > line), and yes I want to run it (as far as I now dot means that I want
to
> > execute file in current shell)
> > I think awk is the right tool, but any other way is also welcome

> [ snip]

> This description is different from the pseudocode in your original post.
> So i can only assume what you might want to do:

> #! /bin/ksh
> INPUTFILE=/path/to/inputfile  #adjust
> a=5

> while read -r cmd ; do
>    while [ "$a" -gt `ps -ef |grep -c [i]mp` ] ; do
>       sleep 2    ## adjust
>    done
>    eval $cmd
> done <$INPUT_FILE

> Regards
> Juergen

 
 
 

awk question

Post by John » Sat, 28 Dec 2002 22:27:22




> > John, tnx for answer,
> > I didn't want to get into details, but here it is
> > a is a number, let's say 5
> > b is number of  oracle imp processess (so I got to assign something like
> > b=`ps -ef |grep imp|wc -l`)
> > /tmp/temp exe is not copy of $INPUT_FILE, it contains only one line (line by
> > line), and yes I want to run it (as far as I now dot means that I want to
> > execute file in current shell)
> > I think awk is the right tool, but any other way is also welcome

> [ snip]

> This description is different from the pseudocode in your original post.
> So i can only assume what you might want to do:

> #! /bin/ksh
> INPUTFILE=/path/to/inputfile  #adjust
> a=5

> while read -r cmd ; do
>    while [ "$a" -gt `ps -ef |grep -c [i]mp` ] ; do
>       sleep 2    ## adjust
>    done
>    eval $cmd
> done <$INPUT_FILE

There are a couple of problems which the OP might encounter.

When counting Oracle imp processes, if ps | grep imp matches
itself, then the count will be wrong. Do you [the OP] have the pgrep command?

Is the purpose is to start new imp commands as the old ones finish,
whilst keeping the load bearable?

There might be a better way of measuring the load on Oracle
of these imp [import] processes -- ask in comp.databases.oracle.server

You probably want to run these processes in the background.

If the sleep is long, then there might be an unnecessarily long
delay when more than one new process can be started (like right
at the beginning, or if several running imp's end at the same time).
(If the sleep is short compared to the run-time of an imp process,
then this does not matter.)

John.

 
 
 

awk question

Post by Yok » Sat, 28 Dec 2002 23:22:13


John, yes, I will run import processes in background, and everything you
said stands.
Z






> > > John, tnx for answer,
> > > I didn't want to get into details, but here it is
> > > a is a number, let's say 5
> > > b is number of  oracle imp processess (so I got to assign something
like
> > > b=`ps -ef |grep imp|wc -l`)
> > > /tmp/temp exe is not copy of $INPUT_FILE, it contains only one line
(line by
> > > line), and yes I want to run it (as far as I now dot means that I want
to
> > > execute file in current shell)
> > > I think awk is the right tool, but any other way is also welcome

> > [ snip]

> > This description is different from the pseudocode in your original post.
> > So i can only assume what you might want to do:

> > #! /bin/ksh
> > INPUTFILE=/path/to/inputfile  #adjust
> > a=5

> > while read -r cmd ; do
> >    while [ "$a" -gt `ps -ef |grep -c [i]mp` ] ; do
> >       sleep 2    ## adjust
> >    done
> >    eval $cmd
> > done <$INPUT_FILE

> There are a couple of problems which the OP might encounter.

> When counting Oracle imp processes, if ps | grep imp matches
> itself, then the count will be wrong. Do you [the OP] have the pgrep
command?

> Is the purpose is to start new imp commands as the old ones finish,
> whilst keeping the load bearable?

> There might be a better way of measuring the load on Oracle
> of these imp [import] processes -- ask in comp.databases.oracle.server

> You probably want to run these processes in the background.

> If the sleep is long, then there might be an unnecessarily long
> delay when more than one new process can be started (like right
> at the beginning, or if several running imp's end at the same time).
> (If the sleep is short compared to the run-time of an imp process,
> then this does not matter.)

> John.

 
 
 

awk question

Post by Jonathon Isaac Swidersk » Sun, 29 Dec 2002 17:26:05


"Juergen Heck" suggested:

Quote:

> >    while [ "$a" -gt `ps -ef |grep -c [i]mp` ] ; do

"John L" responded:

Quote:> When counting Oracle imp processes, if ps | grep imp matches
> itself, then the count will be wrong. Do you [the OP] have the pgrep command?

Thus the [] in the grep command:  When making the match, grep will
interpret the brackets and match 'imp'.  But the grep process itself will
list as 'grep [i]mp', which *won't* match.

An alternative way to do this is

        ... | grep -c imp | grep -v grep ...

but this is longer for only minor (if any) benefit.

--

cs.oberlin.edu/~jswiders  \\  www.dangercat.net/resume

Tombstone: Here lies an atheist; all dressed up and no place to go.

 
 
 

1. Simple awk question

I am trying to build on an example in the O'Reilly book on 'sed'
and 'awk', but not getting anywhere. The example is the script
'filesum' starting on page 160.

Even the following script fails:

=====

#!/bin/csh -f

ls -l $* | nawk '{   \
           BEGIN { print "BYTES" } ;  \
               {  sum += $5 ;  \
                  ++filenum ;  \
                  print $5  }    \
           }'
======

even though it works without the BEGIN line. I have very
limited experience with 'awk' (just simple one liners').
Checking various websites did not help. Any pointers
on where to look up on the use of 'awk' within C shell
scripts would be welcome.

thanks

--


                         Remove 'bounceback' for email address

2. Cmdline args to Sun Workshop.

3. Awk Question - Again

4. What Xserver (Maybe I need to update my install)

5. SED & AWK Question...

6. IC PHYSICAL DESIGNERS - icdesign.fly [1/1]

7. sed/awk question

8. Pings from @Home

9. awk question

10. awk question: getline with no argument

11. awk question

12. HELP: awk question

13. AWK Question???????