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



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
Remove Trailing spaces after a delimiter kiran_418 UNIX for Dummies Questions & Answers 1 04-29-2008 03:19 PM
How to remove trailing spaces mahek_bedi UNIX for Dummies Questions & Answers 2 08-10-2007 08:21 AM
remove trailing newline characters shweta_d Shell Programming and Scripting 7 06-05-2007 10:29 AM
trailing question mark in filename devoetfd UNIX for Dummies Questions & Answers 3 06-09-2006 11:45 AM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 11:48 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0