Re: grep - how to exclude fields ? (112 Views)
Reply
Super Advisor
Piotr Kirklewski
Posts: 339
Registered: ‎01-12-2007
Message 1 of 8 (112 Views)
Accepted Solution

grep - how to exclude fields ?

Hi there

bdf |grep /stand

output:

/dev/vg00/lvol1 295024 59344 206176 22% /stand

I nead o exclude all but lvol1 and /stand

Can anyone help ?

Cheers
Jesus is the King
Please use plain text.
Honored Contributor
john korterman
Posts: 1,117
Registered: ‎11-15-2000
Message 2 of 8 (112 Views)

Re: grep - how to exclude fields ?

Hi,


try something like this:

$ bdf | grep stand| awk '{print $1,$NF}'

regards,
John K.
it would be nice if you always got a second chance
Please use plain text.
Honored Contributor
Oviwan
Posts: 692
Registered: ‎11-29-2005
Message 3 of 8 (112 Views)

Re: grep - how to exclude fields ?

Hey

bdf | grep /stand | awk ' { print $1" "$NF}'

Regards
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 8 (112 Views)

Re: grep - how to exclude fields ?

HI:

The simple way:

# bdf|grep -v -e /stand -e lvol1

Regards!

...JRF...
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,580
Registered: ‎05-19-2003
Message 5 of 8 (112 Views)

Re: grep - how to exclude fields ?

With grep you get whole lines.
No ifs or buts.
So grep needs help, typically awk or cut.
John K, shows a fine example of this helping.

However, why not let awk (or perl) do it all?

$ bdf | awk '/stand/ {print $1,$NF}'

Also, somehow I'm thinking this is not your end goal. What problem are you really trying to solve ?!

Regards,
Hein.
Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 6 of 8 (112 Views)

Re: grep - how to exclude fields ?

... and to fix one other problem that you haven't yet anticipated, I suggest that you use bdfmegs rather than bdf. Bdfmegs is a Bill Hassell script that almost always outputs like bdf. The "almost always" is the significant part. Search the Forums for bdfmegs and you should have no trouble finding it.
If it ain't broke, I can fix that.
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 7 of 8 (112 Views)

Re: grep - how to exclude fields ?

to get JUST the output:

lvol1 stand

run:

bdf | grep /stand | sed -e "s/\// /g" -e "s/ */ /g" | cut -d " " -f 4,9

Note: the first sed expression has a single space before the "/g", and the second one has *two spaces* after the "s/" and a single space before the "/g".

I'm guessing that since you know that /stand is in vg00 you're not interested in the whole /dev/vg00/lvol1 part of the string.

"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
Honored Contributor
TwoProc
Posts: 2,202
Registered: ‎01-11-1999
Message 8 of 8 (112 Views)

Re: grep - how to exclude fields ?

Lots of ways to get that done, mainly because there are a number of sources for that information: commands "df" and "bdf", as well as files "/etc/fstab" and "/etc/mnttab" .

An easier one than the previous posting would be:

> df | grep stand | cut -b -15,33-42

And actually
> df -n | grep stand

gets you pretty close to what you asked for w/o stream edits.


If you're wanting make sure to avoid the "bdf" line wrap problem indirectly mentioned in a previous posting use the contents /etc/mnttab instead:

> grep stand /etc/mnttab | cut -d "/" -f 4,5 | cut -d " " -f 1,2

gives:

lvol1 /stand

"[That boy] is about as sharp as a sack of wet mice" - Foghorn Leghorn
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation