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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert data types in ksh ?

Status
Not open for further replies.

rogers42

Technical User
Mar 30, 2007
64
CA
Hi Folks,

A snippet of my Korn shell script is as follows

c1=`grep -c "AAA" file1`
c2=`grep -c "BBB" file2`
Total = $c1 + $c2

I have tried changing the variable types from char to integers using "typeset -i c1" command but that did not help

Any suggestions to how I can add c1 & c2 ?

Thanks in advance

rogers42
 
It can also be done in one long line (in Korn Shell), without creating c1 or c2 as follows:

Total=$(( $(grep -c "AAA" file1) + $(grep -c "BBB" file2) ))


I hope that helps.

Mike
 
Both the suggestions are very helpful.

Thanks

rogers42

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top