| | |
Converting percentage to a number
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
Hello,
I am trying to use the awk command to print two columns. One of them has a percentage value. This is for file system monitoring. When i try to read it from a file it does not recognize the precent sign and ignores it. How can i convert it or skip the % sign when using this command?
Any help would be appreciated.
Thanks.
Shawn
#! /usr/bin/ksh
HOST=`hostname`
cd /home/orabp1/scripts
/usr/bin/df -g | grep -i /bp1db01_bk|awk '{print $7" "$4}' > fs_usage
if [ `cat fs_usage |awk '{print $2}` -gt 36 ]
then
mailx -s "Backup Filesystem Usage in $HOST has exceded" acvd@drede.com < fs_usage
fi
bckp_chk.sh[7]: 35%: 0403-012 A test command parameter is not valid
I am trying to use the awk command to print two columns. One of them has a percentage value. This is for file system monitoring. When i try to read it from a file it does not recognize the precent sign and ignores it. How can i convert it or skip the % sign when using this command?
Any help would be appreciated.
Thanks.
Shawn
#! /usr/bin/ksh
HOST=`hostname`
cd /home/orabp1/scripts
/usr/bin/df -g | grep -i /bp1db01_bk|awk '{print $7" "$4}' > fs_usage
if [ `cat fs_usage |awk '{print $2}` -gt 36 ]
then
mailx -s "Backup Filesystem Usage in $HOST has exceded" acvd@drede.com < fs_usage
fi
bckp_chk.sh[7]: 35%: 0403-012 A test command parameter is not valid
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
Shell Scripting Syntax (Toggle Plain Text)
... /usr/bin/df -g | grep -i /bp1db01_bk|awk '{sub (/%/, "", $7); print $7" "$4}' > fs_usage ...
Your code is sub-optimal, but that don't matter because it isn't running 1,000,000 times a second. It'll work.
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
That worked perfect but now i get this error msg for the next line.
My dumb brain can't figure out how to fix it
if [ `cat fs_usage |awk '{print $2}` -gt 36 ]
I tried to change it and put another quotation mark but it didn't solve the issue.
"0403-012 A test command parameter is not vaild."

Your awk code is missing the closing apostrophe. And you'll probably find $1 has the numeric value to compare.
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
That's what happens when you've been looking at the problem too long. I'm going through the same thing now on my own project ('updating' Smoothwall Express to use LFS 6.4). Boy am I overlooking stuff that doesn't become obvious very quickly!![]()
Your awk code is missing the closing apostrophe. And you'll probably find $1 has the numeric value to compare.
Thanks for your help previously.
![]() |
Similar Threads
- convert letter to number filled with errors (C++)
- Converting Any Base to Any Base (C)
- Tic-Tac-Toe Game (Visual Basic 4 / 5 / 6)
- Converting a string to number (MS SQL)
- Please help............ (VB.NET)
- hop over decimal and straight to business (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: Korn shell hangs
- Next Thread: Simple script
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





