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 04-14-2008
Heathe_Kyle Heathe_Kyle is offline
Registered User
  
 

Join Date: Oct 2006
Posts: 15
Remove trailing G

Hello, I am trying to write a script that will calculate the amount of data remaining in a storage volume. I'm running Tru64 Unix version 5.1B patch kit 6. The script is being run against an AdvFS domain. I am programming in Korn Shell version M-11/16/88f.

The basic idea is that I want to run df -h and grep for the domain in question. I then pipe that output into awk to extract the two fields I want and store them in variables. I've made it this far with my script.

So now I have two variables: total and remaining. Both hold a number followed by the letter G (for Gigabytes).

I want to remove the trailing G and then take the 2 numbers that are left and print the difference. What I'm stumped on is how to remove the trailing 'G'.

I know that in sed, I could do something like:

new_variable=`sed 's/[0-9].*G$//g'`

to remove the trailing G, but to my knowledge you can't pass a shell variable into sed, so I don't think the following would work:

total=`sed 's/${total}$//g'`

So now my program has 2 variables that both hold a number followed immediately by the letter G. I know I could probably use cut, but the number of characters differs each week. This week, total might be 4 characters with a trailing G, next week it might only be 3. What tool can I use to remove the 'G' and save just the number back into the variable? I think if I could make it passed this step I could figure the arithmetic part out.

Thanks.