![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 02:25 PM |
| String manipulation in TCL | jehrome_rando | Shell Programming and Scripting | 1 | 07-15-2008 09:23 AM |
| How to use sed for string manipulation | hikrishn | Shell Programming and Scripting | 2 | 06-16-2008 12:43 PM |
| String manipulation | jerrynimrod | Shell Programming and Scripting | 2 | 06-05-2008 12:06 PM |
| String manipulation | mr_bold | UNIX for Dummies Questions & Answers | 2 | 02-14-2007 07:48 AM |
![]() |
|
|
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/,/}
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#
|
|
||||
|
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 for example. 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
Now I get a different error. If it is not clear what could be wrong, any pointers for debugging awk would be appreciated. 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 The first line of the script is: Code:
#!/bin/sh |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|