Search code examples
linuxsed

sed search multiple strings in one file


I want to search multiple strings in the same file So far I have this working but one string only

sed -n '/XXX/,+1p'  FILE > FILE

But I want

sed -n '/XXX/YYY/ZZZ/,+1p'  FILE > FILE

I could not make it work.


Solution

  • Use \| to separate multiple patterns to match.

    sed -n '/XXX\|YYY\|ZZZ/,+1p'  INFILE > OUTFILE
    

    Also, the input file has to be different from the output file (if you want to overwrite the file you should use the -i option rather than redirecting to the input file).