Novice Needs help with piping 
Author Message
 Novice Needs help with piping

I have a script just adding two numbers, but I need to be able to pipe
it back to itself.  Instead of explaining here is my script:

#Called add2
nawk 'BEGIN \
{
 if (ARGC==3)
 {
  solution=ARGV[1]+ARGV[2]
  printf "%d\n",solution
 }
 else if (ARGC==2)
 {
  getline numb
  solution=ARGV[1]+numb
  printf "%d",solution
 }

Quote:
}' $*

Problem:  add2 3 4|add2 5

This should give me back 12, but I get an error at the getline.  I
can't figure how else to recieve the 3+4.  Can anyone help me with a
command for this?

Phiz



Fri, 10 Sep 2004 15:37:47 GMT  
 Novice Needs help with piping


.

Quote:
> I have a script just adding two numbers, but I need to be able to pipe
> it back to itself.  Instead of explaining here is my script:

> #Called add2
> nawk 'BEGIN \
> {
>  if (ARGC==3)
>  {
>   solution=ARGV[1]+ARGV[2]
>   printf "%d\n",solution
>  }
>  else if (ARGC==2)
>  {
>   getline numb

Try getline numb < "-" here - you need to tell awk to look on stdin for
the number that you want to read.  Depending on the nawk you may have to
use "-" to represent stdin.  In gawk you would use "/dev/stdin" to
achieve the same effect.

Quote:
>   solution=ARGV[1]+numb
>   printf "%d",solution
>  }
> }' $*

> Problem:  add2 3 4|add2 5

> This should give me back 12, but I get an error at the getline.  I
> can't figure how else to recieve the 3+4.  Can anyone help me with a
> command for this?

> Phiz

HTH
--
Peter S Tillier
"Who needs perl when you can write dc in sed?"
peter dot tillier at btinternet dot com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.


Fri, 10 Sep 2004 15:05:54 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Novice needs help with running a script through a pipe

2. RB Novice needs help

3. Novice needs help with SQL (Max,Min, etc) queries on RealDBs

4. Allen TX C55 novice needs help

5. Novice Needs CW4.0 help

6. Novice Needs Help with complicated report design.

7. Novice needs help....

8. COBOL novice needs test help

9. Novice needs help with FX Ruby

10. Novice Needs Help with Memory Dump Program

11. Need help with Verilog (novice).

12. ASM-novice needs HELP...

 

 
Powered by phpBB® Forum Software