Visit Our UNIX and Linux User Community


Awk command for search a string in lspv


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk command for search a string in lspv
# 1  
Old 09-21-2009
Lightbulb Awk command for search a string in lspv

I 've got this retourn when i tape the commande lspv:

hdisk0 00c3fce454950416 rootvg active
hdisk1 00c3fce454950416 rootvg active

I want to verify if hdisk0 et hdisk1 have the same pvid (ex : 00c3fce454950416)?
Can you help me with the awk command for exemple.

thanks Smilie
# 2  
Old 09-21-2009
Hi khalidou13,
I'm not good with awk, but the following script using sed works fine.
Code:
result=$(lspv)
pvid0=$(sed -nr 's/hdisk0 ([[:alnum:]]+) .*/\1/p' <<< "$result")
pvid1=$(sed -nr 's/hdisk1 ([[:alnum:]]+) .*/\1/p' <<< "$result")
if [[ $pvid0 == $pvid1 ]]; then
    echo "same pvid"
else
    echo "different pvid"
fi

Hope this helps
Santiago
# 3  
Old 09-21-2009
With awk:
Code:
lspv| grep rootvg| awk '{a=$2; getline; if(a!=$2){print "different"}else{print "same"}}'

# 4  
Old 09-21-2009
Computer

It's good !!
Thank you for your help !!
Smilie
# 5  
Old 09-21-2009
Quote:
Originally Posted by zaxxon
With awk:
Code:
lspv| grep rootvg| awk '{a=$2; getline; if(a!=$2){print "different"}else{print "same"}}'

Is the grep bloc absolutely necessary?
Code:
lspv| awk '/rootvg/{a=$2; getline; if(a!=$2){print "different"}else{print "same"}}'

# 6  
Old 09-21-2009
With just adding /rootvg/ to awk you'll get 2 lines as output for every line "lspv" hands over to awk. It's not compact but it works. If you want to use grep not and still only 1 line as output you will have to change the awk part a bit. I was lazy so that's why I was so typing so inefficient Smilie
# 7  
Old 09-21-2009
Depending on the O/P of the lspv command here is another approach:
Code:
lspv | awk '/rootvg/{a[$2]++}!(a[$2]%2){print "same"}'


Previous Thread | Next Thread
Test Your Knowledge in Computers #155
Difficulty: Easy
Defense Advanced Research Projects Agency (DARPA) initiated the ARPANET, the precursor to the Internet, in 1969.
True or False?

10 More Discussions You Might Find Interesting

1. AIX

Lspv -free command on VIOS

Hi all, We have observed that lspv -free command tooks 15 to 20 minutes to display the free disks and we have only 77 MPIO disks on VIO Server. Our VIOS version is 2.2.1.4. Please let us know what could be the reason that lspv -free command taking long time to display the output. Thank (4 Replies)
Discussion started by: m_raheelahmed
4 Replies

2. Shell Programming and Scripting

Awk:String search more than one time and capture OP

Dear All During one of mine script developemnt i am stuch at one sub part. Requiremnt is as below kindly help me. IP file: 2015-02-28 10:10:15 AL M UtranCell UtranCell=RTE001X (unavailable) 2015-02-28 10:10:15 AL M UtranCell UtranCell=RTE001Y (unavailable) 2015-02-28 10:10:15 AL M... (6 Replies)
Discussion started by: jaydeep_sadaria
6 Replies

3. UNIX for Advanced & Expert Users

Pass variable to awk command search string

I must have forgot how to do this, but, I am attempting to enter a variable into an awk / gawk search pattern. I am getting a value from user input to place in a specific section of a 132 character string. my default command is .... gawk --re-interval '/^(.{3}P .{4}CYA.{8}1)/' ... (3 Replies)
Discussion started by: sdeevers
3 Replies

4. AIX

Lspv -free command on VIOS

Hi all, When we run lpsv -free command on VIOS, it will take lot of time to display free disks i.e around 8 to 10 minutes. VIOS ioslevel is 2.2.1.4Can you have any solution for this problem? Many Thanks (2 Replies)
Discussion started by: m_raheelahmed
2 Replies

5. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

6. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

awk search between 2 digits a string

I would like to search between two a string. I thought this would be easy. The is always at the beginning of a line. The code: gawk '/^/{d=$1},/searchstring/,/^(d+1)/' or gawk '/^/,/searchstring/,/^/' did not return the desired result. inputfile.txt 999 some text searchstring some... (6 Replies)
Discussion started by: sdf
6 Replies

9. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

10. Shell Programming and Scripting

Awk command for search a string in lspv

I want to know wich hdisk have only one pvid and also display hdisk with two pvid. hdisk1 00c3fcd4e516183f testvg active hdisk2 00c3fcd4e516189b testvg active hdisk3 00c3fcd4e51618ec testvg ... (1 Reply)
Discussion started by: khalidou13
1 Replies

Featured Tech Videos