0
grep '[:digit:]{1,}-{1,}' *.txt| wc -l 

This command outputs: 0

grep '1-' *.txt| wc -l 

However, this command outputs: 10598

Both commands are being run from the same directory. The first command should have returned greater than or equal to the output of the second command. Can anyone shed some insight about what is going on here?

1
  • You generally want to use grep -c over grep | wc -l Commented Aug 12, 2013 at 20:51

1 Answer 1

3
echo 1 | grep '[:digit:]' #nothing.... 

grep uses a different syntax, you need [[:digit:]] or [0-9].

The {1,} syntax is not supported by basic grep, you can use other modes, like the extended one with -E... Note: Normally one would use + for matching one or more characters....

General note: always test regexes in small parts to see that each part really does what you thought it does. Once the expression gets complicated, it's really hard to tell what went wrong.

Sign up to request clarification or add additional context in comments.

4 Comments

I think it does. But it's [[:digit:]]
@JacobKrall because (according to the manual) that is really not supported
And for {1,} without -E, you could use \{1,\}. Or just \+
Or [0-9]... zillions of different ways.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.