Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trim a string in shell script

Status
Not open for further replies.

sourabhjha

Programmer
Jan 13, 2002
121
IN
Hi,
Need some help reg shell script. I have a shell script which gets the filesystem space usage percentage and displays it. Here is the piece of script which does that.

filesystem=${arr[$i]}
spaceusage=`df -k|grep $filesystem|awk ' { print $5 } '`
echo ${arr[$i]}"="$spaceusage

don't bother about the array. "arr[$i]" basically is the filesystem name which is passed as a parameter. So if i pass the parameter to the program like "$myscipt.sh /test/file" the output will be "/test/file=30%"

Now what i want here is to remove that "%" in the output which is displayed. So the output should look like "/test/file=30".
Can someone tell please me the appropriate substring commands which i can use for the same.

Thanks in advance,
-Sourabh
 
Gigured it out.
spaceusage=`df -k|grep $filesystem|awk ' { print $5 } '|tr -d "%"`


-Sourabh
 
spaceusage=`df -k | awk '$0 ~ fs { print $5+0 }' fs="${filesystem}"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
#var="/test/file=30%"
#print ${var%%%*}
/test/file=30

Or you might want to make it literal with a \ as in:

print ${var%%\%*}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top