Consider the following example, where grep is used to search in binary mode:
$ echo "test blabla test ertytey" | grep -ao tes
tes
tes
I can add a ‘dot’ in the search pattern, to “match any character” and show the next character after the match:
$ echo "test blabla test ertytey" | grep -ao tes.
test
test
… or more dots, to match subsequent characters:
$ echo "test blabla test ertytey" | grep -ao tes...
test b
test e
Let’s say now I want to match a number of characters (say 30, no: 3) after the match; and I read from man grep: {n} The preceding item is matched exactly n times.. So I try:
$ echo "test blabla test ertytey" | grep -ao tes.{3}
$
… nothing happens;
$ echo "test blabla test ertytey" | grep -ao tes.\{3\}
$
… nothing happens;
$ echo "test blabla test ertytey" | grep -ao tes[.]\{3\}
$
… nothing happens;
$ echo "test blabla test ertytey" | grep -ao tes\[.\]\{3\}
$
… nothing happens.
Any ideas what would the correct syntax be to match “any character” (dot) a given number of times in grep’s binary mode?
Many thanks in advance for any answers,
Cheers!
EDIT: as @aix’ answer points out, initially I made a mistake of specifying 30 characters to search for, whereas the string in the example is not long enough 🙂 Have now changed it to the more reasonable count of 3 🙂
First of all,
{30}matches exactly thirty characters, and your string isn’t long enough.Secondly, your grep might require the
-Eflag to enable the extended syntax (mine does).The following works for me: