![]() |
|
|
google unix.com
|
|||||||
| Forums | Casino | Register | Forum Rules | Links | Albums | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| String manipulation using ksh | zambo | UNIX for Dummies Questions & Answers | 5 | 09-18-2008 01:25 PM |
| String manipulation in TCL | jehrome_rando | Shell Programming and Scripting | 1 | 07-15-2008 08:23 AM |
| How to use sed for string manipulation | hikrishn | Shell Programming and Scripting | 2 | 06-16-2008 11:43 AM |
| String manipulation | jerrynimrod | Shell Programming and Scripting | 2 | 06-05-2008 11:06 AM |
| String manipulation | mr_bold | UNIX for Dummies Questions & Answers | 2 | 02-14-2007 06:48 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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/,/}
Code:
sum 1,977,920 830,016 1,147,904 830,016 ./test.sh: bad substitution Code:
bash-3.00# export abc=830,123
bash-3.00# echo ${abc/,/}
830123
bash-3.00#
|
| Sponsored Links |
|
|||
|
I guess you havn't specify the shell in script. (Do not remember how that line is named..)
First line in script Code:
#! /usr/bin/bash In bash it works fine, but I have tried it in ksh: Code:
> ec $used_space
830,016
> ec ${used_space/,/}
ksh: ${used_space/,/}: bad substitution
>
|
|
|||
|
I am sorry, I am still having issues. I changed the code as follows:
Code:
myMethod
used=`myMethod | awk '{gsub(/,/,""); print $3}'`
echo $used
Code:
bash-3.00# ./test.sh sum 1,977,920 795,648 1,182,272 awk: syntax error near line 1 awk: illegal statement near line 1 bash-3.00# stty: : I/O error Code:
#!/bin/sh |
|
|||
|
Thanks, nawk did the trick.
|
|||
| Google The UNIX and Linux Forums |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|