Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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"
Highlighted
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