Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiplication using awk

Status
Not open for further replies.

satpati

Technical User
Dec 4, 2009
2
FR
Dear all,

I am a beginner of awk.

my input file is :

1
2
3

I want to multiply each element of the columns
so that my output will be

1*2*3 = 6

How can i do this using awk.

thanks

regards
 
Hi

I guess it would be useless to ask you what have you tried so far.
Code:
awk 'BEGIN{m=1}{m*=$0;printf"%s%s",(NR>1?"*":""),$0}END{print"="m}' /input/file
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Dear feherke,

Thank you very much.

I apologizes for the very simple query.

Thanks again

regards

satpati
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top