![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Remove Trailing spaces after a delimiter | kiran_418 | UNIX for Dummies Questions & Answers | 1 | 04-29-2008 02:19 PM |
| How to remove trailing spaces | mahek_bedi | UNIX for Dummies Questions & Answers | 2 | 08-10-2007 07:21 AM |
| remove trailing newline characters | shweta_d | Shell Programming and Scripting | 7 | 06-05-2007 09:29 AM |
| trailing question mark in filename | devoetfd | UNIX for Dummies Questions & Answers | 3 | 06-09-2006 10:45 AM |
| Leading and Trailing Spaces | sleepster | Shell Programming and Scripting | 7 | 10-29-2003 11:48 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
That did the trick! I added the sed command to the end of the pipeline I was using to gather the data. So my pipeline looks like:
Code:
df -h | grep <search string> | tail -1 | awk '{ print $2 }' | sed 's/\(.*\)./\1/'
![]() |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|