Well, I tried to edit the other answer, which is incorrect as it currently stands. But the edit was rejected, so I'll have to post my own answer, given that comments are "second class citizens on the Stack Exchange network, not designed to hold information for all eternity [and] may get cleaned up at any time."
As mentioned in the other answer, the -e
option only supports basic regular expressions (meaning that +
does not have special meaning). Therefore the -E
option should be used for extended regular expressions, which support the +
metacharacter.
In addition, grep only supports POSIX regular expressions, which do not recognize \t
as a tab character. The easiest way to fix this, while still maintaining readability and without using any experimental grep options (such as -P
) is to replace [ \t]
with [[:space:]]
.
Therefore the fixed script looks like:
#!/bin/sh
if ! grep -q -E "1[[:space:]]+2[[:space:]]+3" test.txt; then
echo "not found"
else
echo "found"
fi