0

I am using this command to filter out the line set timing on;

type filea.sql | findstr /v "^set timing on;$"

and the output,I'm getting is as follows:

whenever sqlerror exit 9;

grant select on exfdsfds;


exit;

The content of filea.sql is:

set timing on;
whenever sqlerror exit 9;

grant select on exfdsfds;

timing on; cool

exit;

Why is it removing timing on; cool?What modifications to command are needed to avoid such results?

1 Answer 1

3

As documented in findstr /? you need to use /c if you want to match a whole string containing spaces:

Use spaces to separate multiple search strings unless the argument is prefixed with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or "there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for "hello there" in file x.y.

If you want to use ^ and $ you also need /r, otherwise the string will be treated as a literal string instead of a regular expression.

type filea.sql | findstr /v /r /c:"^set timing on;$"

Without /c the command removes all lines containing any of the given words from the output, which includes the line timing on; cool because there's a match for the word timing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.