Q:

Can I multiply pattern match in SED address to print

I have:
/.*213[0-9]\{3\}.*/ {p}

printing all lines with a 6 digit number beginning 213
but would like to update to print all lines with a 6 digit number beginning 213 or 214
Was thinking this should work:
/.*213[0-9]\{3\}.*|.*214[0-9]\{3\}.*/ {p}

or
/.*213|214[0-9]\{3\}.*/ {p}

but I think the syntax or logic is wrong.
Could anyone help?
Thanks

A:

Try this,
/.*21[34][0-9]\{3\}.*/ {p}

Expanded command,
sed -n '/.*21[34][0-9]\{3\}.*/{p}' file

see the regex part ,/.*21[34][0-9]\{3\}.*/. In this, the first number must be 2, and the second number must be 1 and the third number [34] must be 3 or 4 followed by any three digit number. Corresponding line would be printed if the condition is satisfied.

