Re: Print all lines after a line with given string (267 Views)
Reply
Honored Contributor
Jeff_Traigle
Posts: 1,354
Registered: ‎03-04-2004
Message 1 of 5 (267 Views)
Accepted Solution

Print all lines after a line with given string

Trying to extract the device files for mirrors from lvdisplay. This works, but I'm thinking there must be a slightly better command string to do it:

lvdisplay -v ${LV} | awk '/LE PV1/,EOF' | grep -v "LE PV1" | awk '{print $2, $5}' | sort -u
--
Jeff Traigle
Outstanding Contributor
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 2 of 5 (267 Views)

Re: Print all lines after a line with given string

Jeff:

From "Handy one-liners for SED" (attached):

# print section of file from regular expression to end of file
sed -n '/regexp/,$p'


Pete

Pete
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 5 (267 Views)

Re: Print all lines after a line with given string

Hi Jeff:

# lvdisplay -v ${LV} | perl -nle 'if (/0000/../ /){@a=split;$dev=$a[1]." ".$a[4];$m{$dev}++};END{for (sort keys %m) {print}}'

Regards!

...JRF...
Honored Contributor
Peter Nikitka
Posts: 1,575
Registered: ‎02-10-2003
Message 4 of 5 (267 Views)

Re: Print all lines after a line with given string

Hi,

an awk suggestion:
lvdisplay -v ... |
awk '/LE PV1/ {out=1;next}
out {print $2,$5}' |
sort -u

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Honored Contributor
Jeff_Traigle
Posts: 1,354
Registered: ‎03-04-2004
Message 5 of 5 (267 Views)

Re: Print all lines after a line with given string

Thosee awk and perl solutions worked. Of course, seeing JRF's test for LE 00000 made me realize I was making it too difficult to start with... the first LE in an LV is always going to be 00000 so simplifies life looking for that instead of the column headers. (My mind was already on vacation, I guess.) This compressed awk option works fine too.

/usr/sbin/lvdisplay -v ${LV} | awk '/00000/,EOF {print $2, $5}' | sort -u
--
Jeff Traigle
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.