Extract content between lines using line numbers, grep, sed, awk

At first find where the necessary content shows up for example:
grep -m1 -n wpa_supplicant.conf /etc/network/interfaces
this will report us line number 9:
9:wpa_conf /etc/wpa_supplicant/wpa_supplicant.conf
Now I can extract content between this line including itself. For example from line 7 to 9:
sed -n '7,9p' /etc/network/interfaces
Or using awk:
awk 'NR >= 7 && NR <= 9' /etc/network/interfaces

No comments: