Solved

Search Batch file

Posted on 2004-04-29
10
1,481 Views
Last Modified: 2010-08-05
Hi im using this to search a file for the word hotfix..


type C:\lab\tempRegistryextract.txt|findstr -i "hotfix" > C:\Lab\%Computername%.txt


however i would like to be able to now search for lines which contain "XPQ  i need to include the " in the search, how can i do this ?
0
Comment
Question by:gisvpn
  • 2
  • 2
  • 2
  • +3
10 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10949558
I don't follow you exactly.
You need to find both hotfix and XPQ? in the same line?

type c:\lab\tempRegistryextraxt.txt|find /i "hotfix"|find /i "XPQ" >> C:\lab\%computername%.txt
0
 

Author Comment

by:gisvpn
ID: 10949724
i need to search for the actual string "XPQ i would like the " included as the string it searches
0
 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10949755
I think he wants to search for the word "XPQ
where the double quote is insert the search string.

I think you can 'escape' the double quote by using a backslash. i.e.
find "\"XPQ"
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10949834
I don't think you can escape it with \ or ^....
See this PAQ - it explains a way around it: http:Q_20566636.html
0
 
LVL 11

Accepted Solution

by:
griessh earned 500 total points
ID: 10949925
Hi gisvpn,

You can do what CoolBreeze said:

type C:\lab\tempRegistryextract.txt|findstr /i \"XPQ > C:\Lab\%Computername%.txt

You only need the quotes around your search string if that string contains separators like blanks. In your case "\"XPQ" will have the same search results as \"XPQ

You don't have to pipe the text file into findstr either.

findstr /i \"XPQ C:\lab\tempRegistryextract.txt > C:\Lab\%Computername%.txt

will do what you want:-)

Run "help findstr" in a command window and it will tell you:

  \x       Escape: literal use of metacharacter x

and

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
        [/C:string] [/G:file] [/D:dir list] [/A:color attributes]
        [strings] [[drive:][path]filename[ ...]]

======
Werner
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:CoolBreeze
ID: 10950059
what a mistake i made, I actually meant findstr, not find. the escape character is for findstr.
for find, maybe you can try " as the escape character. i.e. """XPQ"
0
 
LVL 10

Expert Comment

by:Kavar
ID: 10950067

 
gisvpn , you still messing with this batch stuff for searching the registry?? When am I going to convince you that there is a MUCH better way??
0
 

Author Comment

by:gisvpn
ID: 10950094
Kavar

haahhaahahah - this is a project im just finishing ! Lots more coming !
0
 
LVL 3

Expert Comment

by:kar10s
ID: 10950157
Hi,

type c:\lab\tempRegistryextraxt.txt|find  "hotfix"|find """XPQ" >> C:\lab\%computername%.txt

above line will find all the lines that contain both the word hotfix and "XPQ
I have eliminated /i parameter to difference between capital and small letter( nor Hotfix or "xpq ..)
Observe use of 3 " to find "XPQ
Regards
0
 
LVL 3

Expert Comment

by:kar10s
ID: 10950197
uff , too slow
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countPairs challenge 7 66
topping1 challenge 7 73
Non-recursive backtracking, using a stack 1 102
C# Error - Add Failed 12 78
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now