Quantcast
Channel: How to select first occurrence from between two patterns including them - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 3

Answer by Philippos for How to select first occurrence from between two patterns including them

$
0
0

Your first sed example doesn't work for the second and following blocks, because /!/q (the backslash may lead to undefined behaviour, so I drop it) is already executed for the first ! and the script stops there (same for the exit of the awk script). So execute it only after the block, use

sed -n '/2\/1\/6.2062/,/!/{p;/!/q;}'

But a simple

sed -n '/2\/1\/6.2062/,/!/p'

like in your second attempt will also work, if you have no problem with wasting some cpu cycles.

And for future scripts, I suggest to use a different delimiter of the address pattern if it contains slashes like

sed -n '\_2/1/6.2062_,/!/p'

Easier to read, right?

And yes, you can also use !d:

sed '\_2/1/6.2062_,/!/!d'

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>