The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-20-2008
illcar illcar is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 9
string manipulation issue

I have myMethod that gives me available,used,free disk space in KB. I parse the used disk space using awk. That gives me something like 830,016. I want the output to be 830016 so that I can add 100000 to it. In other words I would like to use used_space variable in numeric calculations (using expr).

Code:
.....
myMethod
used_space="`myMethod | grep sum | awk -F' ' '{print $3}'`"
echo $used_space
echo ${used_space/,/}
But the last line above gives me error:
Code:
sum                 1,977,920      830,016    1,147,904
830,016
./test.sh: bad substitution
What can I do? If I do the same thing on command line it works fine!
Code:
bash-3.00# export abc=830,123
bash-3.00# echo ${abc/,/}
830123
bash-3.00#