Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to get the exact match of a path ("\Users\sachin.a.goyal\Desktop\test\") which is there in a file:

 Biggest.txt:
 1 number: 
 name = DMS 3.0 R2 - Deployment Workbook_APAC v4_WMT 
 size = 15634835 
 path = \Users\sachin.a.goyal\Desktop\test\ 
 2 number: 
 name = Scenarios 
 size = 254 
 path = \Users\sachin.a.goyal\Desktop\test\New folder\

I am using this command:

 findstr /x /c:"\Users\sachin.a.goyal\Desktop\test\" Biggest.txt

But after this command, DOS window is stucked. It is not giving any error but looks like it is expecting some other parameter. Please help.

share|improve this question
    
Which operating system? It could be MS-DOS, but it is most likely just the command prompt in Windows [something]. I'm tagging the post "Windows" for the time being. If it explicitly is MS-DOS, feel free to change it. –  Daniel Andersson Aug 8 '12 at 7:38

1 Answer 1

up vote 0 down vote accepted

The /x is not going to work as the entire line needs to match the search string, and in this case, it is prefixed with path =. Also, the \ symbols need to be escaped so they are not interpreted as commands. Finally, regular expression mode will help capture the right line, as it ends in a space then the end of line - the end of line can be represented as a $:

H:\>findstr /r /c:"\\Users\\sachin.a.goyal\\Desktop\\test\\ *$" biggest.txt
path = \Users\sachin.a.goyal\Desktop\test\

The reason for your search hanging is probably one of the \ was matching a command.

If you are using a variable to hold the path being searched for, you would still need to escape the backslashes. You can do this with the replace feature:

set path="c:\Users\sachin.a.goyal\Desktop\test\"
set path=%path:\=\\%
echo path
c:\\Users\\sachin.a.goyal\\Desktop\\test\\

The second line says, replace all backslahes with double backslashes. Unfortunately I don't have a Windows box to test on right now, but you may need to escape the backslashes still:

    set path=%path:\\=\\\\%
share|improve this answer
    
Thank you very much!!It worked. But The actual problem is that I have stored the path in a variable and I am matching the value of that variable in file. Then I have to save the path in the variable as you told with regular expression '\' ? –  Sachin Aug 8 '12 at 7:34
    
Yeah that should be fine - are you still getting stuck with the backslashes? –  Paul Aug 8 '12 at 13:56
    
Yes....that variable contains the path with single backslashes only –  Sachin Aug 8 '12 at 17:22
    
Can you test it by populating the var with double backslashes and if it works we'll figure a way to fix it –  Paul Aug 8 '12 at 21:55
    
Yes it works when populate the var like that code set var = \\Users\\sachin.a.goyal\\Desktop\\test\\ *$ –  Sachin Aug 9 '12 at 6:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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