Kaseya Community

getting all text after a certain string

  • Hi,

     

    Can anyone suggest a good way that I can get, in to a variable, all the text on one line of a text file, after a certain string?

    So I have

     

    Address=56,sdfsdf,sdfsdf

    Name=John Bloggs

    Size=Small

    Type=Big

     

    I want to get the Name of the person, so I need everything after "Name=" but only on that line (ie not the rest of the data, Size, Type etc).

     

    Any ideas?

    Olly

  • Tricky one ;)  You could maybe use a batch file - this would look at sourcefile.txt, and echo back everything after Name= within:

    @ECHO OFF

    FOR /F "tokens=*" %%R IN ('find "Name=" sourcefile.txt') DO SET VAR=%%R

    ECHO %VAR:~5%

  • Yeah I had to make a VB script to do that nicely, I'm still not completely happy with it but at least it works. If you know anything about VB scripting then you might want to  use the Replace function or you could look at Regular Expressions which I think could also be used to find what you want in a text file.

    If you use Sam's batch script you might want to type or pipe it out to another text file and then grab it with a Get Variable - File Content or you could give Ben's "Execute Shell Command - Get Results to Variable" procedure command a go to get it back into a variable.