Jump to content

Recommended Posts

Posted

I was talking to an excel m8 the other night and i assumed this task could be done in excel but it appears not as simple as i thought it was so i thought id ask you guys.

I have a text file in this format and i will recieve more of them so it will be an ongoing thing

:: Dub.com Toolbar
start /wait msiexec /qn /norestart /x {8e5025c2-8ea3-430d-80b8-a14151068a6d}

:: 1k.FM Toolbar
start /wait msiexec /qn /norestart /x {3a9262ef-45b5-46fc-b460-7053539c9176}

So i use replace in notepad to change it like this

:: Dub.com Toolbar
'|{8e5025c2-8ea3-430d-80b8-a14151068a6d}' & _  ;  
:: 1k.FM Toolbar
'|{3a9262ef-45b5-46fc-b460-7053539c9176}' & _  ;

Labourious but simple enough but here's the tricky bit

I need to add the titles of the uninstaller at the end of the files like this example

'|{8e5025c2-8ea3-430d-80b8-a14151068a6d}' & _  ;  Dub.com Toolbar
'|{3a9262ef-45b5-46fc-b460-7053539c9176}' & _  ;  1k.FM Toolbar

So i can copy it into my script and the array will work and there is the problem how to automate that part?

Also if a uninstaller has multiple entries like this

'|{8e5025c2-8ea3-430d-80b8-a14151068a6d}' & _  ;  Dub.com Toolbar
'|{A957F04C-49F4-4375-8C8A-D04B769EFE47}' & _  ;  
'|{1bc82e67-afbc-434a-aae9-eb0776452f05}' & _  ;  
'|{4D84CC03-383C-4BB1-A485-B263A03E9FF1}' & _  ;  
'|{3a9262ef-45b5-46fc-b460-7053539c9176}' & _  ;  1k.FM Toolbar

I only need it to move the title to the first entry not the subsequent ones

So any thoughts on how to solve this?

Posted (edited)

Regular expression for example could be used https://regex101.com/r/wW9fX3/1, though you will need to piece it together using that regexp I have provided (based on the info above) and StringRegExp(). I would, but I think it's good practice for you to try it yourself, as I take it that this is for your job as well as the help file being pretty informative.

Hint: For simplicity _FileReadToArray() and then regexp every third line or something along those lines, so you could use Mod($i, 3) or something similar.

 

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 11/5/2015 at 7:30 PM, guinness said:

 (https://regex101.com/r/wW9fX3/1),

Just as note:   https://regex101.com/r/wW9fX3/1

closing paranthesis ....

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Sweet regex exercise  :D
Not so difficult though
But I don't understand well the 'multiple entries' thing, what should the initial text file look like in this case ?

Posted

@mikell : I think it looks like this :

:: Dub.com Toolbar
start /wait msiexec /qn /norestart /x {8e5025c2-8ea3-430d-80b8-a14151068a6d}
start /wait msiexec /qn /norestart /x {A957F04C-49F4-4375-8C8A-D04B769EFE47}
start /wait msiexec /qn /norestart /x {1bc82e67-afbc-434a-aae9-eb0776452f05}
start /wait msiexec /qn /norestart /x {4D84CC03-383C-4BB1-A485-B263A03E9FF1}


:: 1k.FM Toolbar
start /wait msiexec /qn /norestart /x {3a9262ef-45b5-46fc-b460-7053539c9176}

 

Posted (edited)

I am no regex master but this is very close.

I took the context of your file before you did any modification and created this script.

#Include <StringConstants.au3>

$sFile = FileRead(@ScriptDir & "\doc.txt")
$sFile = StringStripWS($sFile, $STR_STRIPALL)
$sFile = StringRegExpReplace($sFile, "(?i)::(.+?ToolBar).+?({.+?})", "'|$2' & _  ; $1" & @CRLF)
MsgBox(0, "", $sFile)

 

doc.txt

Capture.JPG

Edited by ViciousXUSMC
Posted

I can see this thread escalating into multiple solutions and getting no where close to what is required. A lot more details should be provided before any real solution is provided, hence why I have only shown @Chimaera where to look and for them to continue to meet their requirements.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Id say my result looks like what he wants :) just what are the chances everything's ends in "toolbar" and what happens if there is more than one uninstall string (just repeat the last capture group).

But no harm in chiming in with a (partial) solution gives us all a chance to learn bits and pieces from each other.

Posted (edited)
  On 11/5/2015 at 8:56 PM, ViciousXUSMC said:

Id say my result looks like what he wants :) 

I don't think so, you missed the part about multiple entries.

  On 11/5/2015 at 8:56 PM, ViciousXUSMC said:

But no harm in chiming in with a (partial) solution gives us all a chance to learn bits and pieces from each other.

Well I have seen it happen too often around here with these regular expression threads, that too much white noise leads to very little in the way of learning. A parsing related question such as this, should have a thorough description of the expected input and output, as well as all the possible scenarios in between.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Assuming the 'Toolbar' is only in the example, this should work generically

$txt = FileRead("1.txt")

$r1 = StringRegExpReplace(StringRegExpReplace($txt, '.*(\{.+\})', "'|$1' & _  ;"), '::\s*(.+\R)(.+)\R?', "$2   $1")
; optional, remove empty lines :
$r2 = StringRegExpReplace($r1, '(?m)^\s*\R?', "")

Msgbox(0,"", $r2)

Edit
Obviously - as said guinness rightly - this should work until a new and unexpected requirement occurs  :D

Edited by mikell
Posted

@Guiness I agree more input is better for parsing.  

I like to throw what I know and see what sticks, often somebody can  use what I know and it may be the one piece they did not think of (often the inexperienced like myself are the ones that come up with some off the wall solution) most of what I have learned so far is from the back and forth in other threads where somebody had a "solution" and somebody pointed out why that was not the best solution and how this way works better.  

But I get your gist, esp with RegEx threads they are quite notorious around here :) I am glad I have hit a level that I can at least chim in a bit so people can continue to teach me.

Posted
  On 11/5/2015 at 9:06 PM, mikell said:

Assuming the 'Toolbar' is only in the example, this should work generically

$txt = FileRead("1.txt")

$r1 = StringRegExpReplace(StringRegExpReplace($txt, '.*(\{.+\})', "'|$1' & _  ;"), '::\s*(.+\R)(.+)\R?', "$2   $1")
; optional, remove empty lines :
$r2 = StringRegExpReplace($r1, '(?m)^\s*\R?', "")

Msgbox(0,"", $r2)

 

This example seems to work the best, but there's still some errors, ive got a few endings that are not the same so ill look into that and see what i can come up with.

Many thanks, at least its possible :)

I might try and build in the manual bits as well

Posted
  On 11/5/2015 at 9:01 PM, guinness said:

Well I have seen it happen too often around here with these regular expression threads, that too much white noise leads to very little in the way of learning. A parsing related question such as this, should have a thorough description of the expected input and output, as well as all the possible scenarios in between.

Two thoughts

A: i didn't know it was a regex question and ive never heard of parsing

B: I thought i gave a thorough explanation, maybe its the diff between programmers like yourself and hobby lads like me.

Intellectually I agree with your comment about white noise but i'm an adjuster i take what scraps i find around the forum and adjust them into something that's nasty and not good code but it works for the limited stuff i do. 99% of my stuff is read an array and run it against a cmd action. And i mostly reuse what i have

I try my best to write code properly (as i understand it) but it does get rained on when i post sometimes ;)

And i try not to ask to often as well because i dont want to rely on everyone here

I would imagine if i stop working in the pc shop i will prob stop coding as well, its a thing i do for a few hrs a week to try and make my life easier, i dont have the drive some of you lads have.

That said it doesn't mean i don't appreciate the help as many have been really kind in the years i have been here.

Posted
  On 11/5/2015 at 9:58 PM, Chimaera said:

A: i didn't know it was a regex question and ive never heard of parsing

B: I thought i gave a thorough explanation, maybe its the diff between programmers like yourself and hobby lads like me.

Parsing is quite a general term and something you should have come across over the years on the Forum. As for the "hobbyist" comment, I just don't see the relevancy nor should it be used as some excuse. I am a hobbyist as well!

As demonstrated already, you clearly have a specific set of rules for how your file is laid out that you would like to parse (read and translate into something different). Therefore it's best if you come up with all possible scenarios. Try and re-read your post and think ... "What would I need to know to help this user? Should they know about the alternative line endings? Would it help to have more examples? Maybe I should demonstrate an example of a file I would like to parse?" 

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

My regexes are infinitely better because of the regex gamesmanship exhibited by folks like JGunich and Mikell.  The desire to foolproof something against edgecases before the question is fully formed is part of the learning, you just learned something else instead.   Helping the OP in their efforts is secondary to getting all that shit on one line first.

I would attribute most of my success with Splunk and WQL directly to learning PCRE in this forum.  The ability to write good RegEx is as marketable as any other language, the enjoyment of it even moreso.  And I have found the best place to learn regex is not some other website, it is right here.   The user picks any regular expression or any string and says that, 'my regex is the best' or 'this cant be done' , and a lessonplan will be personalized.  For $0.

 

Wouldnt use it for this task tho, I would read the notepad into an array, and as long as those colons are reliable (I know mine isnt).  

#include<array.au3>

local $array[7]

$array[0]='::Dub.com Toolbar'
$array[1]='|{8e5025c2-8ea3-430d-80b8-a14151068a6d}'
$array[2]='|{A957F04C-49F4-4375-8C8A-D04B769EFE47}'
$array[3]='|{1bc82e67-afbc-434a-aae9-eb0776452f05}'
$array[4]='|{4D84CC03-383C-4BB1-A485-B263A03E9FF1}'
$array[5]='::1k.FM Toolbar'
$array[6]='|{3a9262ef-45b5-46fc-b460-7053539c9176}'

For $i = ubound($array) - 2 to 0 step - 1
    If stringleft($array[$i], 2) = "::" Then
        $array[$i + 1] = $array[$i + 1] & " ; " & $array[$i]
        _ArrayDelete($array , $i)
    EndIf
Next

_ArrayDisplay($array)

 

Edited by boththose
removed line continuations

  Reveal hidden contents

Posted (edited)

boththose,
To fit the exact OP's requirements your code should be slightly modified

For $i = ubound($array) - 1 to 0 step - 1
    If stringleft($array[$i], 2) <> "::" Then
        $array[$i] = "'" & $array[$i] & "' & _  ; "
    Else
        $array[$i + 1] = $array[$i + 1] & StringTrimLeft($array[$i], 2)
        _ArrayDelete($array , $i)
    EndIf
Next

Anyway your array method is probably more versatile than a one-liner regex if some adaptations are further needed for 'particular' cases  :)

Edited by mikell

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...