Reputation: 5044
I have difficulties understanding how to specify special characters ^
and "
as parameters in windows command prompt.
I am using gnuwin32's diff
in Win 7 . It has a -I
option that accepts a regular expression from the command line. I want to invoke diff
in a batch file specifying a regular expression. However, my regular expression is a complex one with ^ "
and white-space special characters within it:
^[ \t]*#[ \t]*include[ \t]+"c:\\program files
I'm not able to understand Windows's rules for specifying special characters in the command line in this case which has special rules regarding ^
and "
. How am i going to specify the above regular expression in the command line?
I guess it should look like this:
diff -I "^[ \t]*#[ \t]*include[ \t]+"c:\\program files" file1 file2
But the "
in the middle mess up the whole thing. How should I deal with the ^
and "
?
Upvotes: 0
Views: 370
Reputation: 5044
After some research and testing, this should be the regex required:
diff -I "^[[:space:]]*#[[:space:]]*include[[:space:]]\+\"c:\\\\program file" file1 file2
For one thing, diff
is using grep
style regex which doesn't support the Perl style \t
sequence. We need to use \"
to specify a literal "
.
Also, do not use windows batch file to test the parameter passed to a program as I did.
In other words, never think this batch file diff.bat
with a few echo
s can help you test which command line arguments to use:
echo %1
echo %2
echo %3
echo %4
Write and compile a program for this and have it dump the command line arguments.
Upvotes: 0