Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

Findstr batch file - need help

I need a batch file that will extract certain strings in a csv file for multiple servers.  The path would be c:\apps\*.csv.  I want the extracted data into a output.txt file.  I just need lines containing the strings.

I would like two input files...
string.txt = phrases containing strings to search for
server.txt = servers to check in a certain path

I will reward points asap!

Thanks!
0
mystikal1000
Asked:
mystikal1000
  • 3
  • 3
  • 2
  • +2
2 Solutions
 
Gerwin Jansen, EE MVETopic Advisor Commented:
If I understand right, you need to search in file "server.txt" for strings that are in "string.txt" and send output to "output.txt".

With findstr you would do this:
findstr /g:string.txt server.txt > output.txt

Open in new window


When string.txt contains:
server1
server3
server8

Open in new window

And server.txt contains:
test this server 1
test that server1
test every server3
test other server5

Open in new window


output.txt would contain:
test that server1
test every server3

Open in new window



0
 
mystikal1000Author Commented:
No I need to search c:\apps\*.csv files that includes strings from string.txt.  I need it to search for each server in the servers.txt file.

%server%\c$\appse\*.csv

Hope it makes sense.
0
 
leighyoungCommented:
vbscript ok or does it require Batch?
0
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 
mystikal1000Author Commented:
I like batch, vbscript is fine too.  Love to get some solutions soon!
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
So server.txt contains your servers to check, OK.

This would do just fine:

for /f %f in (server.txt) do @findstr /g:string.txt \\%f\c$\apps\*.csv >> output.txt

Open in new window


You output.txt looks like this:

\\<server>\c$\data\<somefile>.csv:<line matches string from string.txt>
0
 
paultomasiCommented:
As a batch file this might look something like the following:

@echo off

for /f %%a in (server.txt) do (
   findstr /g:string.txt \\%%a\c$\apps\*.csv >>output.txt
)

Open in new window

0
 
Bill PrewCommented:
@mystikal1000

I'd ask that you consider closing this question slightly differently.  If 36710813 was the solution you used that's fine, but I feel like gerwinjansen should have at least gotten an assist and a chuck of the points. His post 36708296 is essentially the exact same thing, only he delivered the syntax you could use right from a command prompt rather than in a BAT file.  paultomasi clarified that to use it in a BAT file you simply have to change the FOR loop variables to be referenced with %% instead of %.

Ultimately it's your call, but in reading this question I felt like gerwinjansen should have gotten some recognition for his contribution to the ultimate solution.

~bp
0
 
mystikal1000Author Commented:
How do I reward points to both?
0
 
Bill PrewCommented:
Use the request Attention link near your original question and ask a moderator to reopen the question so you award points differently.  Here are a couple of useful links from the Help area.

http://www.experts-exchange.com/help.jsp#hs=29&hi=409

http://www.experts-exchange.com/help.jsp#hs=29&hi=407

~bp
0
 
paultomasiCommented:
It has to bourne in mind mystikal1000 was quite specific in stating: "I need a batch file that will...".

Personally, I'd vote for leaving the award as it is and marking this one up as a lesson to be learned: Read the question!

As harsh as that may appear to sound, it's the difference between delivering and NOT delivering what was asked for.

I can provide you with a long list of experts who would have given almost identical (if not exactly the same) code as that given in the solution. In that case, one would have to consider who answered first.

It is astute of billprew to draw attention to this - perhaps he should consider becoming an EE Moderator.
0
 
paultomasiCommented:
You gotta be kiddin' - the last ferrari cost me two t-shirts !!
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now