1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

command line in windows to pick text from a line of text

Discussion in 'Scripting & Programming' started by Mikeyboy, Dec 7, 2012.

  1. Mikeyboy

    Mikeyboy Kilobyte Poster

    spent a few hours today trying to work this out... I need to run a command which can pick a portion of text from a one line text file...

    the point is to pick out text from an event log, part of which is a section saying CLSID {ABC-5123-XXX-ETC}

    it has text before and after the {}, I just need the text between the wiggly brackets...

    help please :)
    Certifications: VCP,MCSA, MCP, MCDST, MCITP, MCTS, A+, N+
  2. shadowwebs

    shadowwebs Megabyte Poster Forum Leader

    Which language script are you trying to run it with? Will you be using Powershell?
    Certifications: compTIA A+, Apple Certified Technical Coordinator 10.10 (OS X Yosemite, Server and Support)
  3. SimonD

    SimonD Terabyte Poster Moderator

    Do you already know what the text is you're searching for? I only ask because I am wondering if Grep for Windows will do it?
    Certifications: CNA | CNE | CCNA | MCP | MCP+I | MCSE NT4 | MCSA 2003 | Security+ | MCSA:S 2003 | MCSE:S 2003 | MCTS:SCCM 2007 | MCTS:Win 7 | MCITP:EDA7 | MCITP:SA | MCITP:EA | MCTS:Hyper-V | VCP 4 | ITIL v3 Foundation | VCP 5 DCV | VCP 5 Cloud | VCP6 NV | VCP6 DCV | VCAP 5.5 DCA
    WIP: VCP6-CMA, VCAP-DCD and Linux + (and possibly VCIX-NV).
  4. TechS

    TechS New Member

    Hi Mikeyboy

    Not sure if this will help, I do this sort of search sometimes when checking for VPN disconnections in event logs. As shadowwebs suggested, which scripting language will you be using?

    Within PowerShell maybe you could try something like the following...

    Get-EventLog -Logname System | Where-Object {$_.message -like "*CLSID*"} | Format-List | Out-File C:\CLSID.txt

    Which should output what you need to a text file where you can copy/paste the relevant text.

    Then something like Get-Content -Path C:\CLSID.txt | Select-String "CLSID {"

    To get just the parts needed.

    Most likely much better ways of doing this but just a few thoughts.
    Certifications: MCDST, MCITP (Vista), MCTS (Vista), MCITP EDST (Win 7), MCTS (Win 7)
    WIP: Security +
  5. Mikeyboy

    Mikeyboy Kilobyte Poster

    Hey dudes, gonna say no power shell, as it will be running on 2003 server, any server, so have to assume it wont have any additional components installed... Its ok to involve grep or something, anything which can be just an.exe copied to the server and run (the idea is to automate).
    I dont know what the text will be unfortunately, just that it will be in a text file, and between the { and } character, only one instance of this in the text file.. is it possible? Managed to use some FOR command in a bat file to remove all text after the }, so if it was possible to remove all text before the {, that would work! But I dont know how...

    Oh and cheers techs, that would be great if I could use powershell but I think I have to discount PS for now...
    Last edited: Dec 8, 2012
    Certifications: VCP,MCSA, MCP, MCDST, MCITP, MCTS, A+, N+
  6. Beerbaron

    Beerbaron Megabyte Poster

    Could you use PERL?
    Certifications: BSc (Hons), MSc, ITIL v3F, MCP, MCDST, MCITP: edst7, MCTS, MCSA: Server 2003, MCSA: Windows 7, N+, NVQ IT lvl 3, MCSA Windows 7, VCP5, CCENT, CEH
  7. Mikeyboy

    Mikeyboy Kilobyte Poster

    erm... I dont know? Unless its native to server 2003, then probably not? If its a file I can just copy over, run the command, and then delete, then yes :)
    Certifications: VCP,MCSA, MCP, MCDST, MCITP, MCTS, A+, N+
  8. Mikeyboy

    Mikeyboy Kilobyte Poster

    just an update, managed to get what I wanted to working. I used a grep command to pick the line of text containing the required string, and then found a perl script which was able to remove all text before and after specified characters (in my case, { and }). With both of these I didn't need to install anything, just copied the EXE and DLL files over and deleted them when done :D
    Certifications: VCP,MCSA, MCP, MCDST, MCITP, MCTS, A+, N+

Share This Page