LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-12-2009, 01:01 AM   #1
jtbinuya
LQ Newbie
 
Registered: Aug 2007
Posts: 11

Rep: Reputation: 0
I need help w/ bdf command to produce only the filesystem name and its value


I need help with a script I'm making. Suppose I have this value

# bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 524288 208456 313400 40% /
/dev/vg00/lvol1 505392 73152 381696 16% /stand
/dev/vg00/lvol8 4718592 3474560 1244032 74% /var
/dev/vg00/lvol7 8192000 1581736 6558680 19% /usr
/dev/vg00/lvol6 6144000 4687544 1445824 76% /tmp
/dev/vg00/lvol5 8192000 2130048 6014672 26% /opt
/dev/vg00/lvol4 4194304 1648032 2526416 39% /home
/dev/vg00/lvol9 14336000 46258 13885428 0% /apps
/dev/odm 0 0 0 0% /dev/odm
/dev/vx/dsk/dg18/lvol2
25165824 18710677 6051706 76% /u26
/dev/vx/dsk/dg18/lvol3
25165824 16662669 7971714 68% /u27
/dev/vx/dsk/dg18/lvol1
25165824 8644390 15488863 36% /u25
/dev/vx/dsk/dg18/lvol4
25165824 16662669 7971714 68% /u28

---------

I only need to print out the following relevant fields:

40% /
16% /stand
74% /var
19% /usr
76% /tmp
26% /opt
39% /home
0% /apps
0% /dev/odm
76% /u26
68% /u27
36% /u25
68% /u28

so I can make a mailing script to inform me what filesystem is already at the threshold of 80%. I tried to use the cut command but because of the long filesystem name of some of the filesystems, they end up being one whole column encompassing the kbytes column. I don't know what else to do...any assistance would be very much appreciated.

Thanks
 
Old 01-12-2009, 01:10 AM   #2
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466
Blog Entries: 6

Rep: Reputation: 51
I believe in teaching a person to learn how to do catch a fish rather than providing him a fish directly.
Read this :
Consider a slight variation on the company.data file we've been playing with in this section:

406378:Sales:Itorre:Jan
031762:Marketing:Nasium:Jim
636496:Research:Ancholie:Mel
396082:Sales:Jucacion:Ed

If you want to print just columns 1 to 6 of each line (the employee serial numbers), use the -c1-6 flag, as in this command:

cut -c1-6 company.data
406378
031762
636496
396082

If you want to print just columns 4 and 8 of each line (the first letter of the department and the fourth digit of the serial number), use the -c4,8 flag, as in this command:

cut -c4,8 company.data
3S
7M
4R
0S

And since this file obviously has fields delimited by colons, we can pick out just the last names by specifying the -d: and -f3 flags, like this:

cut -d: -f3 company.data
Itorre
Nasium
Ancholie
Jucacion

Here is a summary of the most common flags for the cut command:

-c [n | n,m | n-m] Specify a single column, multiple columns (separated by a comma), or range of columns (separated by a dash).
-f [n | n,m | n-m] Specify a single field, multiple fields (separated by a comma), or range of fields (separated by a dash).
-dc Specify the field delimiter.
-s Suppress (don't print) lines not containing the delimiter.
 
Old 01-12-2009, 01:15 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,375

Rep: Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755Reputation: 2755
To be honest, if I was dealing with a an output like that ie where the data can be wrapped or not, I'd use Perl.
Its do-able in bash+awk I'd expect, but messy.
http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials
 
Old 01-12-2009, 03:55 AM   #4
jtbinuya
LQ Newbie
 
Registered: Aug 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by your_shadow03 View Post
I believe in teaching a person to learn how to do catch a fish rather than providing him a fish directly.
Read this :
Consider a slight variation on the company.data file we've been playing with in this section:

406378:Sales:Itorre:Jan
031762:Marketing:Nasium:Jim
636496:Research:Ancholie:Mel
396082:Sales:Jucacion:Ed

If you want to print just columns 1 to 6 of each line (the employee serial numbers), use the -c1-6 flag, as in this command:

cut -c1-6 company.data
406378
031762
636496
396082

If you want to print just columns 4 and 8 of each line (the first letter of the department and the fourth digit of the serial number), use the -c4,8 flag, as in this command:

cut -c4,8 company.data
3S
7M
4R
0S

And since this file obviously has fields delimited by colons, we can pick out just the last names by specifying the -d: and -f3 flags, like this:

cut -d: -f3 company.data
Itorre
Nasium
Ancholie
Jucacion

Here is a summary of the most common flags for the cut command:

-c [n | n,m | n-m] Specify a single column, multiple columns (separated by a comma), or range of columns (separated by a dash).
-f [n | n,m | n-m] Specify a single field, multiple fields (separated by a comma), or range of fields (separated by a dash).
-dc Specify the field delimiter.
-s Suppress (don't print) lines not containing the delimiter.
Thanks so much for the replies. I guess I can use the cut command but its going to be messy when it comes to the rows "/u26" and below since these contain very long filenames that the system treated the column for filesystem and kbytes as one whole column. Time to catch some fish.

God Bless
 
Old 01-12-2009, 04:16 AM   #5
jtbinuya
LQ Newbie
 
Registered: Aug 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Cool Got the answer

I searched a few more forums regarding my problem and I believe that I found the answer in NF

Here's the screenshot

Before:

# bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 524288 208456 313400 40% /
/dev/vg00/lvol1 505392 73152 381696 16% /stand
/dev/vg00/lvol8 4718592 3476696 1241896 74% /var
/dev/vg00/lvol7 8192000 1581752 6558664 19% /usr
/dev/vg00/lvol6 6144000 4687544 1445824 76% /tmp
/dev/vg00/lvol5 8192000 2130048 6014672 26% /opt
/dev/vg00/lvol4 4194304 1648056 2526392 39% /home
/dev/vg00/lvol9 14336000 46258 13885428 0% /apps
/dev/odm 0 0 0 0% /dev/odm
/dev/vx/dsk/dg18/lvol2
25165824 18710677 6051706 76% /u26
/dev/vx/dsk/dg18/lvol3
25165824 16662669 7971714 68% /u27
/dev/vx/dsk/dg18/lvol1
25165824 8644390 15488863 36% /u25
/dev/vx/dsk/dg18/lvol4
25165824 16662669 7971714 68% /u28
/dev/vx/dsk/dg18/lvol5
25165824 4374695 19491684 18% /u29
/dev/vx/dsk/dg18/lvol6
25165824 20758685 4131698 83% /u30
/dev/vx/dsk/dg18/lvol8
50000000 42272844 7244212 85% /u32
/dev/vx/dsk/dgorb/lvol1
17408000 13371286 3797165 78% /OraHome
/dev/vx/dsk/dg09/lvol1
52000000 8760446 40553420 18% /ora_archive
/dev/vx/dsk/dg08/lvol1
35280000 34841279 411303 99% /u20
/dev/vx/dsk/dg07/lvol1
24000000 20820885 3043306 87% /u15
/dev/vx/dsk/dg10/lvol2
40000000 34842388 4835264 88% /u17
/dev/vx/dsk/dg03/lvol3
39000000 36890196 1977943 95% /u11
/dev/vx/dsk/dg03/lvol1
41000000 39553085 1356484 97% /u07
/dev/vx/dsk/dg10/lvol1
30168000 29259218 851984 97% /u19
/dev/vx/dsk/dg02/lvol2
40000000 38408165 1492408 96% /u05
/dev/vx/dsk/dg03/lvol2
43000000 40987192 1887009 96% /u09
/dev/vx/dsk/dg02/lvol1
40000000 38119252 1763202 96% /u03
/dev/vx/dsk/dg11/lvol1
35676000 34841352 782485 98% /u16
/dev/vx/dsk/dg11/lvol2
34408000 30745086 3434049 90% /u18
/dev/vx/dsk/dg02/lvol3
41000000 38664759 2189349 95% /u02
/dev/vx/dsk/dg04/lvol1
49000000 47849428 1078663 98% /u08
/dev/vx/dsk/dg05/lvol3
29000000 28695713 285272 99% /u14
/dev/vx/dsk/dg04/lvol3
40000000 39675853 303950 99% /u04
/dev/vx/dsk/dg04/lvol2
48000000 45973227 1900102 96% /u06
/dev/vx/dsk/dg05/lvol2
43000000 39082512 3672647 91% /u12
/dev/vx/dsk/dg05/lvol1
30500000 29720075 731182 98% /u10
/dev/vx/dsk/dg18/lvol7
50000000 47132821 2687984 95% /u31
/dev/vx/dsk/dg17/lvol1
80000000 60905164 17901470 77% /u24
/dev/vx/dsk/dg16/lvol2
37676000 37020921 614139 98% /u23
/dev/vx/dsk/dg16/lvol1
43000000 42267183 687017 98% /u22
/dev/vx/dsk/dg15/lvol1
17000000 10032447 6874920 59% /u21
/dev/vx/dsk/dg01/lvol1
17408000 4713619 11920518 28% /u01
/dev/vx/dsk/dg14/lvol1
27000000 18455089 8010858 70% /redo2
/dev/vx/dsk/dg12/lvol1
27000000 18455089 8010859 70% /redo1

After:

# bdf|awk '{print $(NF-1),$(NF-0)}'|grep %
40% /
16% /stand
74% /var
19% /usr
76% /tmp
26% /opt
39% /home
0% /apps
0% /dev/odm
76% /u26
68% /u27
36% /u25
68% /u28
18% /u29
83% /u30
85% /u32
78% /OraHome
18% /ora_archive
99% /u20
87% /u15
88% /u17
95% /u11
97% /u07
97% /u19
96% /u05
96% /u09
96% /u03
98% /u16
90% /u18
95% /u02
98% /u08
99% /u14
99% /u04
96% /u06
91% /u12
98% /u10
95% /u31
77% /u24
98% /u23
98% /u22
59% /u21
28% /u01
70% /redo2
70% /redo1

I can now make the script with a lot less lines.

Thanks
 
  


Reply

Tags
format, manipulating, output



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unix 'bdf' command cleopard Linux - General 3 06-09-2011 08:19 AM
how to install .bdf files in suse 10.0? noorudin Linux - Software 1 05-30-2006 10:55 AM
how to install bdf files in suse 10.0? noorudin Linux - Software 1 05-30-2006 08:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration