Operating System - HP-UX
1837936 Members
2980 Online
110124 Solutions
New Discussion

Re: how to perform exact match with the awk.

 
SOLVED
Go to solution
Prasad Joshi
Regular Advisor

how to perform exact match with the awk.

Hi All,

I want to remove the some VxVM volumes.

sliam16:/ # vxprint -v
Disk group: dg

TY NAME ASSOC KSTATE LENGTH PLOFFS STATE TUTIL0 PUTIL0
v vol1 fsgen ENABLED 3145728 - ACTIVE - -
v vol2 fsgen ENABLED 3145728 - ACTIVE - -
v vol3 fsgen ENABLED 4096000 - ACTIVE - -
v vol4 raid5 ENABLED 3584000 - ACTIVE - -
v vol5 fsgen ENABLED 806912 - ACTIVE - -
v vol6 fsgen ENABLED 1048576 - ACTIVE - -
v vol6-L01 fsgen ENABLED 1048576 - ACTIVE - -
v vol7 fsgen ENABLED 409600 - ACTIVE - -
v vol7-L08 fsgen ENABLED 58560 - ACTIVE - -
v vol7-L09 fsgen ENABLED 58560 - ACTIVE - -
v vol7-L10 fsgen ENABLED 58560 - ACTIVE - -
v vol7-L11 fsgen ENABLED 58560 - ACTIVE - -
v vol7-L12 fsgen ENABLED 58560 - ACTIVE - -
v vol7-L13 fsgen ENABLED 58560 - ACTIVE - -
v vol7-L14 fsgen ENABLED 58560 - ACTIVE - -
v vol8 fsgen ENABLED 409600 - ACTIVE - -
v vol9 fsgen ENABLED 1843200 - ACTIVE - -
v vol9-L08 fsgen ENABLED 263360 - ACTIVE - -
v vol9-L09 fsgen ENABLED 263360 - ACTIVE - -
v vol9-L10 fsgen ENABLED 263360 - ACTIVE - -
v vol9-L11 fsgen ENABLED 263360 - ACTIVE - -
v vol9-L12 fsgen ENABLED 263360 - ACTIVE - -
v vol9-L13 fsgen ENABLED 263360 - ACTIVE - -
v vol9-L14 fsgen ENABLED 263360 - ACTIVE - -
v vol10 fsgen ENABLED 1843200 - ACTIVE - -

I wan to remove all the volumes of the format vol1 to vol10.

I know this can be done with a for loop. But, I want to do it with the one line command something like this.

vxprint -v | awk '/vol[expression to match no]/ {print $2}' | xargs -n1 vxedit -g dg -rf rm

How could i write a rule with the awk?
I just want to match vol1 to vol10, how could i do it?

Thanks & regards,
Prasad.
8 REPLIES 8
Ninad_1
Honored Contributor

Re: how to perform exact match with the awk.

Prasad,

This can be done with a single line but somtimes its better to do it command for each volume to have more control and may be its less time consuming compared to testing a script/single line command and any bugs that command line may have.
e.g. you post shows the vol6 , vol7 , vol8 as probably some layered volumes - I am not an expert in Veritas VM. so you need not remove the vol7-L08 and so on I guess.
So if this is one time activity why not use command line for every volume.
This is just my view.

Regards,
Ninad
Prasad Joshi
Regular Advisor

Re: how to perform exact match with the awk.

Hi Ninad,

You are right vol7-L** and vol9-L** need not be removed explicittly. Actully, when I remove vol7 (vol9) they will get removed atuomatiacally.

So I just want way to remove all of them in one shot, using on line command.

Thanks for your help.

I have seen you posting replies to many questions. I think you are maharastrian. I am from Pune. Where are you from? (If you have any problems you need not answer.)

Thanks & regards,
Prasad
Ninad_1
Honored Contributor

Re: how to perform exact match with the awk.

You can use
vxprint -v | grep '^v' | awk '{print $2}' | grep -v "-" | xargs -n1 vxedit -g dg -rf rm

But make sure you have unmounted the filesystems using these volumes.

I am from Pune as well.
Mail me at ninaddate at indiatimes.com or rediffmail.com

Regards,
Ninad
LiPEnS
Valued Contributor
Solution

Re: how to perform exact match with the awk.

Hi
use this:

vxprint -v | awk '/vol[1-9](0|[[:space:]])/ {print $2}' | xargs -n1 vxedit -g dg -rf rm

Regards
LiPEnS
Rodney Hills
Honored Contributor

Re: how to perform exact match with the awk.

Rather then excluding, how about specifying the lines you want. If the second column ends with -L.. then keep it.

vxprint -v | awk '$2~/-L..$/{print $2}' | xargs -n1 vxedit -g dg -rf rm

HTH

-- Rod Hills
There be dragons...
Sandman!
Honored Contributor

Re: how to perform exact match with the awk.

imho...sed might be the better tool to use in this case:

# vxprint -v | sed -n 's/.* \(vol[0-9]*\) .*/\1/p' | xargs -n1 vxedit -g dg -rf rm

cheers!
Tim Nelson
Honored Contributor

Re: how to perform exact match with the awk.

Unless I missed something.

vxprint -v |awk '$2 ~ "^vol1$" || $2 ~ "^vol10$"'|while read list
do
remove the filesystems
done

You get the idea..
Prasad Joshi
Regular Advisor

Re: how to perform exact match with the awk.

Hi All,

Thanks for providing me with different ways of doing the same thing.

Thanks & regards,
Prasad