How to remove multiple word from grep command in AIX

2

I am trying to check disks used for mirror in lvs. currently I am using "lslv -m ulv" command but to check for multiple lvs is difficult. I guess there should be some option in grep to exclude repetition of word, because if I will grep "disk" it will show a number of rows.

Hemant

Posted 2012-08-24T10:21:00.087

Reputation: 31

Answers

1

the command that you need is uniq. Supply the output from grep through uniq

grep disk | uniq

Update:

 ~ > cat test
0001 0201 hdisk0
0002 0202 hdisk0
0003 0203 hdisk0
0004 0204 hdisk0
 ~ > cat test | cut -d " " -f 3 | sort -u
hdisk0
 ~ >

I assume you do not need the first two column if the only thing you want to sort by is hdisk0

mnmnc

Posted 2012-08-24T10:21:00.087

Reputation: 3 637

Sorry, but It did not work. lslv -m salvaglv | grep hdisk0 | uniq. it should give only one row with hdisk0. but insted it gave me same output as lslv -m salvaglv | grep hdisk0. – Hemant – 2012-10-03T08:43:16.027

Ok. Please try to use sort -u instead of uniq. Also if you could show us the output of lslv -m salvaglv | grep hdisk0 it could shed some light on by which columns you should sort. – mnmnc – 2012-10-03T08:55:50.813

hemantr:stelsvr> lslv -m salvaglv | grep hdisk0 0001 0201 hdisk0 0002 0202 hdisk0 0003 0203 hdisk0 0004 0204 hdisk0 0005 0205 hdisk0 0006 0206 hdisk0 0007 0207 hdisk0 0008 0208 hdisk0 0009 0209 hdisk0 0010 0210 hdisk0 0011 0211 hdisk0 0012 0212 hdisk0 /u/hemantr
hemantr:stelsvr> lslv -m salvaglv | grep hdisk0 | sort -u 0001 0201 hdisk0 0002 0202 hdisk0 0003 0203 hdisk0 0004 0204 hdisk0 0005 0205 hdisk0 0006 0206 hdisk0 0007 0207 hdisk0 0008 0208 hdisk0 0009 0209 hdisk0 0010 0210 hdisk0 0011 0211 hdisk0 0012 0212 hdisk0 /u/hemantr hemantr:stelsvr>
– Hemant – 2012-10-03T12:32:18.170

i've updated my answer. I assume you do not need the information from first two columns if you want to see only one entry for hdisk0. – mnmnc – 2012-10-03T12:56:29.703