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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cut last value of a variable length string 2

Status
Not open for further replies.

Birbone

MIS
Dec 20, 2000
141
US
The `df -m /tmp |grep -v Free|awk '{print $4}'` command is the basis for this question.

Since the length of the output can vary between a one to three digit percentage, how can I cut it so just the last character (%) so always striped.

-B :cool:
 
# x=$(df -M /tmp |grep -v Free|awk '{print $4}')
# print ${x%%\%*}
 
I am not sure what you are asking...

You don't want the % at the end?

if so, do this.


df -m /tmp |grep -v Free|awk '{print $4}' | sed -e 's/%//'


 
The '-m' is not available on AIX, though '-M' is.
 
kHz.... here's the -M vs. -m options taken from the AIX 5200-04 man pages.

-m Displays statistics in units of MB blocks. The output values for the file
system statistics would be in floating point numbers as value of each unit in
bytes is significantly high.

-M Displays the mount point information for the file system in the second
column.


-B :cool:
 
You can always use file descriptors:

Code:
#!/bin/ksh

df -M /tmp |grep -v Free|awk '{print $4}' | exec 3<&0

while read -u3 df; do
        print -r -- "$df"
done

[bigsmile]
 
Hi,
Just use printf in your awk

df -k /tmp |grep -v Free|awk '{printf "%3d\n", $4}'

Ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top