Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-19
4
Medium Priority
?
373 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
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…

715 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