Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Print all lines after a line with given string

SOLVED
Go to Solution
Highlighted
Honored Contributor 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
1 ACCEPTED SOLUTIONS
Acclaimed Contributor Acclaimed Contributor

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...
4 REPLIES
Outstanding Contributor 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
Acclaimed Contributor Acclaimed Contributor

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