I have a file with lines in the following pattern:136x2340+1564+0that is, <N1>x<N2>+<N3>+<N4>.I'd like to filter (maybe with grep) all lines such that N1 range is from a to b and N2 range is from c to d.The constants a,b,c,d depend on my problem. I'll fix them in the script.I tried egrep '^([0-9][0-9][0-9]x[0-9][0-9][0-9]+)' but the output shows136x2340+1564+0835x428+355+1780817x406+186+747114x1533+1256+456that is, also shows lines with N2 with 4 digits (I supposed only 3 digits).edit: also I'd like to replace x by , (comma), the first + sign by  (empty space) and the second + sign by , (comma) so the output should be N1,N2 N3,N4
Filter strings with numbers in a range and change format
text processing;grep
In grep extended regular expression (ERE) syntax, + is a quantifier meaning 'one or more of the preceding atom'. To match + literally in this context, you need to escape it:egrep '^([0-9][0-9][0-9]x[0-9][0-9][0-9]\+)' file835x428+355+1780817x406+186+747If you want to make substitutions, then grep really isn't the right tool - however if your version of sed has a similar extended regex mode you could use that:sed -En 's/([0-9]{3})x([0-9]{3})\+([0-9]{1,})\+([0-9]{1,})/\1,\2 \3,\4/p' file835,428 355,1780817,406 186,747If you only have basic regular expressions, the escaping becomes harder to read:sed -n 's/\([0-9]\{3\}\)x\([0-9]\{3\}\)+\([0-9]\{1,\}\)+\([0-9]\{1,\}\)/\1,\2 \3,\4/p' file835,428 355,1780817,406 186,747