Sed/awk : to grep only required pattern disk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed/awk : to grep only required pattern disk
# 1  
Old 08-22-2013
Sed/awk : to grep only required pattern disk

Hi Experts,

Need help with the following:

Desired output:
Only want to get the output marked in green.

The file:

Code:
--- Physical volumes ---
   PV Name                     /dev/disk/disk4704
   PV Status                   available
   Total PE                    6399
   Free PE                     1
   Autoswitch                  On
   Proactive Polling           On

   PV Name                     /dev/disk/disk4705
   PV Status                   available
   Total PE                    6399
   Free PE                     1
   Autoswitch                  On
   Proactive Polling           On


   --- Physical volume groups ---
   PVG Name                    pvgDBSST001
   PV Name                     /dev/disk/disk4704
   PV Name                     /dev/disk/disk4705




- The desired output should be below:
Should be taken from the
PHP Code:
--- Physical volumes --- 
portion , and not from --- Physical volume groups --- portion .

Code:
/dev/disk/disk4704
/dev/disk/disk4705




- What I am trying :

Code:
awk '/PV Name/{print $NF}' file
/dev/disk/disk4704
/dev/disk/disk4705
/dev/disk/disk4704
/dev/disk/disk4705


I am getting 4 entry , 2 from top, 2 from bottom, but I do not want the bottom 2 disk.


Thanks,

---------- Post updated at 07:47 PM ---------- Previous update was at 07:41 PM ----------

Also , how to tell awk to filter the data from first portion only , and not go for searching "PV Name" in the second portion.

How to do a mechanism to search in this portion of data:

Code:
--- Physical volumes ---
   PV Name                     /dev/disk/disk4704
   PV Status                   available
   Total PE                    6399
   Free PE                     1
   Autoswitch                  On
   Proactive Polling           On

   PV Name                     /dev/disk/disk4705
   PV Status                   available
   Total PE                    6399
   Free PE                     1
   Autoswitch                  On
   Proactive Polling           On

---------- Post updated at 08:09 PM ---------- Previous update was at 07:47 PM ----------

Solved:
By removing duplicates.

[CODE]awk '/PV Name/{if(A[$NF]++==0) print $NF }'



Thank you all.

Last edited by rveri; 08-22-2013 at 09:18 PM..
# 2  
Old 08-22-2013
See if that fits you.

Code:
awk '/PV Name/ {if (!a[$NF]++)print $NF}'

This User Gave Thanks to Aia For This Post:
# 3  
Old 08-22-2013
Aia ,
Thank you...
# 4  
Old 08-23-2013
Code:
awk '/Physical volume groups/ {f=1} !f && /PV Name/ {print $NF}'
/dev/disk/disk4704
/dev/disk/disk4705

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

2. Shell Programming and Scripting

How to print the lines between the pattern using awk/grep/sed?

Hi, I need a help to search a pattern and print the multiple lines between them. Input file: Tue May 29 12:30:33 EDT 2012:threadWebContainer : 357:com.travimp.hotelierlinks.abba.service.RequestHandler.requestService(String, ITICSDataSet): hotelCancelReservation request: ... (4 Replies)
Discussion started by: aroragaurav.84
4 Replies

3. UNIX for Dummies Questions & Answers

One liner pattern search with awk/sed/grep

I have an array containing bunch of characters. I have to check this array for specific character and if "Not Found than" use a goto statement to go to USAGE set options = (A B C D E F) @ i = 0 while ($i <= ${#options}) if ($options != "F" || $options != "D") then goto USAGE endif @... (1 Reply)
Discussion started by: dixits
1 Replies

4. Shell Programming and Scripting

Help to search multiple pattern in file with grep/sed/awk

Hello All, I have a file which is having below type of data, Jul 19 2011 | 123456 Jul 19 2011 | 123456 Jul 20 2011 | 123456 Jul 20 2011 | 123456 Here I wanted to grep for date pattern as below, so that it should only grep "Jul 20" OR "Jul ... (9 Replies)
Discussion started by: gr8_usk
9 Replies

5. Shell Programming and Scripting

Goto each directory and subdirectories and grep the required pattern

Hi All, I need your help in finding pattern from files present in different directories. I need to search for a pattern "xyz" from "*.txt" files which are present in different levels of directories as shown. example ------- dir1/subdir1/file.txt dir2/subdir2/subsubdir2/file.txt... (5 Replies)
Discussion started by: imas
5 Replies

6. Shell Programming and Scripting

How to awk/sed/grep lines which contains a pattern at a given position

Dear friends I am new to linux and was trying to split some files userwise in our linux server. I have a data file of 156 continuous columns named ecscr final. I want the script to redirect all the lines containing a pattern of 7 digits to separate files. I was using grep to do that,... (2 Replies)
Discussion started by: anoopvraj
2 Replies

7. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

8. Shell Programming and Scripting

Extracting pattern only with AWK | SED | GREP

We have the following statement working in CGYWIN, but when we move the program to Solaris 10 it fails. x=`echo "ABC196925XYZ" | grep -o --only-matching "\{6\}"` How can we use AWK or SED to extract only the number from the string? The following outputs the entire string. We only want... (5 Replies)
Discussion started by: James Clark
5 Replies

9. Shell Programming and Scripting

Split a file based on pattern in awk, grep, sed or perl

Hi All, Can someone please help me write a script for the following requirement in awk, grep, sed or perl. Buuuu xxx bbb Kmmmm rrr ssss uuuu Kwwww zzzz ccc Roooowwww eeee Bxxxx jjjj dddd Kuuuu eeeee nnnn Rpppp cccc vvvv cccc Rhhhhhhyyyy tttt Lhhhh rrrrrssssss Bffff mmmm iiiii Ktttt... (5 Replies)
Discussion started by: kumarn
5 Replies

10. UNIX for Dummies Questions & Answers

grep required pattern and next 2 or 3 lines

dear ones pl.kindly help me 1) how to print(grep) required pattern and following 2 or 3 lines. 2) grep required pattern(to print)+above 2 lines+below 2 or 3 lines.from a report file. ex: we have some report file kf askfjsk fksaj fk skf sjfksjd kff sjfkjs kf jskdjfklsd jfklsdf sdkfjsd fsd... (3 Replies)
Discussion started by: cvvsnm
3 Replies
Login or Register to Ask a Question