grep (bash) multi-line pattern

后端 未结 6 389
感情败类
感情败类 2021-01-15 01:14

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]),

6条回答
  •  伪装坚强ぢ
    2021-01-15 02:02

    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
    

提交回复
热议问题