anybastard Posted April 24, 2013 Share Posted April 24, 2013 (edited) Hi guys ,I need you help with regex and TXT file manipulationThe question is thisI need to change HDD on several units , and new hdd could have different size but must have same structure , so i want manage previous diskpart script file to perform this operationlet's me explain , this is a tipical txt filecreate partition primary size=400 ------------------------> Constant value 1create partition EFI size=300-----------------------------> Constant value 2create partition MSR size=128-----------------------------> Constant value 3create partition primary size=xxxxx ---------------------> Variable valueexitNow I want if possiblecalculate the new hdd size -> OK DONEput constant values on different variablessubtract all constant values from new hdd size and put the difference on variable position ( Variable value ) inside txt fileCan you help me with this regex manipulation ...sorry but I'mno skilled about regexThanks in advance for your help AnyB. Edited May 1, 2013 by anybastard Link to comment Share on other sites More sharing options...
careca Posted April 24, 2013 Share Posted April 24, 2013 (edited) Nice, i didn't know there were diskpart scripts, anyway,i don't see why you would need regex to do what you describe...you seem to need more mathematics than anything else.search for "create partition primary size=400"isolate the numbers to the right of '='use that number to Calculate hdd sizeassign difference to a variablewrite the variable to the file either by lineor the whole file with all variables in the middle Edited April 24, 2013 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
anybastard Posted April 24, 2013 Author Share Posted April 24, 2013 Hi Careca , first for all thanks for your reply . and yes you are right at the end is only mathematic step but my main problem is how "grab" constant values and how put the variable number on correct position Can you make an example ...if possible ? Thanks again AnyB, Link to comment Share on other sites More sharing options...
jdelaney Posted April 24, 2013 Share Posted April 24, 2013 (edited) You can use _FileReadToArray, and loop through the array for key words (StringInStr), then parse out everything right of the '=' (StringInStr, StringRight...or StringSplit).Or, you can use FileRead, and use StringRegExp on the string to find what you need.Try it out, post some code, we'll help debug. Edited April 24, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
anybastard Posted April 24, 2013 Author Share Posted April 24, 2013 Hi Jdelaney , Thanks for the answer parse out everything right of the '='. --> I have different "=" on my txt file and many of these are not necessary please could you make an example based on my file ?? Thanks a lot AnyB. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 24, 2013 Share Posted April 24, 2013 Get text on the right of size= and minimum= - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
jdelaney Posted April 24, 2013 Share Posted April 24, 2013 Re-read my post...emphasis on 'key' words (I bolded it)...key words being: partition primary size|EFI size|etc IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
anybastard Posted April 24, 2013 Author Share Posted April 24, 2013 Hi ... sorry for my mistake I will try Tnx BRs AnyB Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 24, 2013 Moderators Share Posted April 24, 2013 While I am generally a fan of leading the horse to water, I think this one will die of thirst first... Try this, anybastard: #include <Array.au3> #include <File.au3> Local $aArray _FileReadToArray(@DesktopDir & "\LazyGuysTextFile.txt", $aArray) ;Read LazyGuysTextFile.txt to an array For $i = 1 To $aArray[0] If StringInStr($aArray[$i], "create partition ") Then ;search Array for the words "create partition" Select Case StringInStr($aArray[$i], "primary size=") $primarySize = StringRight($aArray[$i], 3) Case StringInStr($aArray[$i], "EFI size=") $EFISize = StringRight($aArray[$i], 3) Case StringInStr($aArray[$i], "MSR size=") $MSRSize = StringRight($aArray[$i], 3) EndSelect EndIf If StringInStr($aArray[$i], "shrink minimum") Then $shrinkMinimum = StringRight($aArray[$i], 4) ;search the array for the words "shrink minimum" Next MsgBox(0, "", "Primary Size: " & $primarySize & @CRLF & "EFI Size: " & $EFISize & @CRLF & "MSR Size: " & $MSRSize & @CRLF & "Shring Minimum: " & _ $shrinkMinimum) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
anybastard Posted April 24, 2013 Author Share Posted April 24, 2013 Hello , lazyGuys ??? LOL I will change with noSkilledguys In anyway thanks to all for your advice and code BRs AnyB Link to comment Share on other sites More sharing options...
anybastard Posted April 24, 2013 Author Share Posted April 24, 2013 Hi JLogan3o13 your file is OK for my purpose ( thanks for that ) , I would ask only a little and last help If StringInStr($aArray[$i], "create partition ") Then ;search Array for the words "create partition" Select Case StringInStr($aArray[$i], "primary size=") $primarySize = StringRight($aArray[$i], 3) Unofrtunatly constant value 1 and variable value have same name so this portion the script save inside $primarySize only 1 of 2 . Is there a way to save both ? Thanks again . BRs An1B Link to comment Share on other sites More sharing options...
kylomas Posted April 24, 2013 Share Posted April 24, 2013 anybastard, Is this going to be part of a loop, or is the file larger? I'ts doubtful that you are writting a program for something you can do in your head, or happens infrequently. I'm asking because it makes a difference to the solutions. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
anybastard Posted April 25, 2013 Author Share Posted April 25, 2013 Hello . the first one it is a part of a loop all the tool function is - Calculate new storage size -> done - Grab all data ( constant ) from old txt -> In progress - recalculate a new storage size -> no problem for this part - write a new value on old txt file -> no problem for this part as you can see my issue is/was how grab all data That's it BRs An1B Link to comment Share on other sites More sharing options...
careca Posted April 25, 2013 Share Posted April 25, 2013 (edited) Opening a file example: $pfile = (@ScriptDir & 'lalalala.txt') FileOpen($pfile, 0) $Read = FileRead($pfile) Posts above have pointed out the direction to go, where did you got stuck? Edited April 25, 2013 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
anybastard Posted April 25, 2013 Author Share Posted April 25, 2013 Hi guys , as you understand I use autoit very rarely ..... OK I don't know if this is elegant way or correct way but seem work fine I made a "preliminary " script to change/modify constant value1 row from size=400 to size1=400 and used JLogan3o13 code in order to have all data necessary ready to use for the next step Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 25, 2013 Moderators Share Posted April 25, 2013 Glad you worked it out... "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
careca Posted April 26, 2013 Share Posted April 26, 2013 Come back when you get stuck, and then, let us know what you have so far. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
anybastard Posted April 26, 2013 Author Share Posted April 26, 2013 Hi Careca , sure , I will do and thanks a lot for your suggestion, advice and.....code BRs An1B Link to comment Share on other sites More sharing options...
anybastard Posted April 28, 2013 Author Share Posted April 28, 2013 (edited) Hello guys ,always me ... I have again a little problem related to "my" scriptThe problem is on this lineshrink minimum=8704-----------------------------> Constant value 3this part of the code is okIf StringInStr($aArray[$i], "shrink minimum:") Then $shrinkMinimum = StringRight($aArray[$i], 4) ;search the array for the words "shrink minimum"I will have shrink minimum: 8704 . This mean that inside specific variable i have correct numeric value for next step .The problem is that this number could be 4 or 5 characters . I mean that on different txt file I could have shrink minimum value 23456 But if i change "StringRight($aArray[$i], 4" and put 5 instead of 4 when I will have on my txt file the value with 4 characters i will have my variable with this value =8704 and this is not ok for my next stepCan you help me to solve this question , please ?BRsAnyB Edited April 28, 2013 by anybastard Link to comment Share on other sites More sharing options...
somdcomputerguy Posted April 28, 2013 Share Posted April 28, 2013 I think with these two functions you can get around however many characters make up the number.StringMid StringInStrI think the = character would need to be a parameter for the StringinStr function.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now