1752805 Members
5762 Online
108789 Solutions
New Discussion юеВ

Script for BDF

 
SOLVED
Go to solution
Leandro Lucena.
Occasional Contributor

Script for BDF

Hey Budies,

Could someone help me regardind cut comand utilization?

I'm making a script and I need to cut the 5th and 6th colums of bdf output(%used and Mounted on).

Thanks,

Leandro!
6 REPLIES 6
Geoff Wild
Honored Contributor

Re: Script for BDF

Why cut when you can awk?


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Jeff Schussele
Honored Contributor
Solution

Re: Script for BDF

Hi Leandro,

awk would be a better tool here - try

bdf | awk '{print $5,$6}'

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Helen French
Honored Contributor

Re: Script for BDF

Try this:

# bdf | awk '{print $5, $6}' > /tmp/bdf_list
Life is a promise, fulfill it!
Mark Grant
Honored Contributor

Re: Script for BDF

Not sure cut is your best best here.

awk is a possibility as in
df | awk '$1 ~ "/dev" { printf "%s %s\n",$4,$5}'

However bdf will split long lines and NFS mounts will break the above.

Here is a perl snippet that deals with all that

@FILESYSTEMS=(`df 2>/dev/null`);

while($filesystem=pop @FILESYSTEMS){
chop($filesystem);

# Dump df output we don't want

next if $filesystem =~ /.*Filesystem.*/;
next if $filesystem =~ /swap.*/;
next if $filesystem =~ /proc.*/;

# get filesystem percentage used (5th field)

($waste1,$waste2,$waste3,$waste4,$percentage,$fs)=split " ", $filesystem;

if($fs eq ""){ # A two line df filesystem
$fs=$percentage;
$percentage=$waste4;
$filesystem=pop @FILESYSTEMS;
}

next if $filesystem =~ /:/; # Lose NFS filesystems

print "Filestem $fs is $percentage used\";
}
Never preceed any demonstration with anything more predictive than "watch this"
Kent Ostby
Honored Contributor

Re: Script for BDF

Leandro --

My filename is called "useme"

cut -d" " -f5,6 useme

#cat useme
The fast brown fox chased after the lazy hare
#cut -d" " -f5,6 useme
chased after
#

The -d determines the delimter for cut to use.
Default is .


Best regards,

Kent M. Ostby

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Romildo
New Member

Re: Script for BDF

Leandro,

Try this script ...

#!/bin/ksh
#
# Author : $Author: b077892 $
# Revision : $Revision: 1.1 $
# Date : $Date: 2001/05/29 16:18:25 $
#
# Header : @(#)$Header: bdf.sh $
#

bdf | awk '
BEGIN {
iLinha=0
}
{
if ( NF == 1 ) {
lin = substr( $1, 1, length( $1 ) )
} else {
iLinha++
if ( NF > 5 ) {
Linha[iLinha]=sprintf("%-30.30s %8s %8s %8s %8s %3s %s",$1,$2,$3,$4,$5,$6,$7 )
} else {
Linha[iLinha]=sprintf("%-30.30s %8s %8s %8s %8s %3s %s",lin,$1,$2,$3,$4,$5,$6 )
}
lin=""
}
}
END {
i=1
while ( i <= iLinha ) {
print Linha[i]
i++
}
}
'


You my select the fields that you need.

Best Regards.

Romildo