Solved

Script to find specific words in a text file and export them to another

Posted on 2011-09-19
4
368 Views
Last Modified: 2012-05-12
Hey guys,

I have exported all my computer names in a certain OU to a txt file using dsquery

Unforntunately it exports the computer names along with the CNs and all that good stuff
"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"

I need to find a way to extract the computername to another txt which they all start with mtlwksxxxx or mtllapxxxx where x is a set of 4 variable digits ,

So in the new txt file i just want the computer names to show

Thanks!
0
Comment
Question by:WBGames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 36562549
Would extracting the information in the format you require by easier?

dsquery computer "ou=whatever,dc=domain,dc=com" -scope onelevel -name mtl* -o rdn > pclist.txt

-o rdn will extract just the relative dn.

Steve
0
 
LVL 7

Expert Comment

by:ednetman
ID: 36562560
What command are you running in dsquery?  I think there is an option to show only the hostname, as opposed to the full OU structure.
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 36563106
When text.txt is your txt file containing:

"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLLAPxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLSRVxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"

This would extract your system names:

for /f "tokens=2 delims==," %f in (test.txt) do @echo %f | findstr "MTLWKS MTLLAP"

Open in new window


Output:

MTLWKSxxxx
MTLWKSxxxx
MTLLAPxxxx
0
 
LVL 1

Author Closing Comment

by:WBGames
ID: 36563113
thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Articles on a wide range of technology and professional topics are available on Experts Exchange. These resources are written by members, for members, and can be written about any topic you feel passionate about. Learn how to best write an article t…
Saved searches can save you time by quickly referencing commonly searched terms on any topic. Whether you are looking for questions you can answer or hoping to learn about a specific issue, a saved search can help you get the most out of your time o…

623 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