In bash (4.3.46(1)) I have some multi-line so called fasta records where each record is initiated by on line with >name and the following lines DNA sequence ([AGCTNacgtn]),
Created sedgrep mixed version to support in generic way... You could use this sedgrep shell command available at https://github.com/iamdvr/sedgrep-shell-util
Direct Link: https://github.com/iamdvr/sedgrep-shell-util/blob/main/sedgrep
For your case direct command is this...
cat | sed -nr ':main; /^>.*chr2/ { :loop; p; n; /^>/ b main; b loop} '
sedgrep usage is as follows...
Default NEW_LINE_PATTERN is ^\[
Usage :
cat {INPUT_FILE_NAME} | sedgrep {NEW_LINE_PATTERN} {THREAD_OR_SEARCH_PATTERN}
cat {INPUT_FILE_NAME} | sedgrep {THREAD_OR_SEARCH_PATTERN}
sedgrep {NEW_LINE_PATTERN} {THREAD_OR_SEARCH_PATTERN} {INPUT_FILE_NAME}
sedgrep {THREAD_OR_SEARCH_PATTERN} {INPUT_FILE_NAME}
Example :
cat sampleInput.log | sedgrep 2016-05-23 DB_CONN
cat sampleInput.log | sedgrep DB_CONN
sedgrep 2016-05-23 DB_CONN sampleInput.log
sedgrep DB_CONN sampleInput.log