Operating System - Linux
1753479 Members
5043 Online
108794 Solutions
New Discussion юеВ

Re: Print all lines after a line with given string

 
SOLVED
Go to solution
Jeff_Traigle
Honored Contributor

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
4 REPLIES 4
Pete Randall
Outstanding Contributor

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
James R. Ferguson
Acclaimed Contributor
Solution

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...
Peter Nikitka
Honored Contributor

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"
Jeff_Traigle
Honored Contributor

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