Anis_Stack
Anis_Stack

Reputation: 3452

Using grep to match one digit with TCL

The file that I want to grep contains many lines.

I want to grep lines which contain only 1 digit: "0" or "1".

I used this command:

exec grep -e "^\[0-1\]{1}$" file

But I got:

child process exited abnormally

What's wrong with RegExp of grep?

Upvotes: 0

Views: 356

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137707

The most common issue when running grep as a Tcl subprocess is that it exits with a non-zero error code when it doesn't find anything at all. This always causes Tcl to throw an exception. The simplest workaround is perhaps this:

exec /bin/sh -c {grep -e '^[0-1]{1}$'; true} < file

Note that we are feeding in the file using a redirection here; this means that it is not necessary to strip the name of the file from the results.

Upvotes: 1

Related Questions