Home>

How can I extract only a specific character string?
grepis in trouble because it will extract the whole line

Example
cat a.txt | grep -E 'occur. * xml'

Results
uim_occurlllxml_niu
uim_occurforlllxml_niu2
uim_occurwhilelllxml_niu3

Ideal
occurlllxml
occurforlllxml
occurwhilelllxml

  • Answer # 1

    I think

    grep should have-ooption.

    cat a.txt | grep -E -o 'occur. * xml'
    occurlllxml
    occurforlllxml
    occurwhilelllxml

Related articles