Jump to content
Sign in to follow this  
anybastard

How manage this txt file

Recommended Posts

anybastard

Hi guys ,

I need you help with regex and TXT file manipulation

The question is this

I 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 operation

let's me explain , this is a tipical txt file

create partition primary size=400 ------------------------> Constant value 1

create partition EFI size=300-----------------------------> Constant value 2

create partition MSR size=128-----------------------------> Constant value 3

create partition primary size=xxxxx ---------------------> Variable value

exit

Now I want if possible

calculate the new hdd size -> OK DONE

put constant values on different variables

subtract all constant values from new hdd size and put the difference on variable position ( Variable value ) inside txt file

Can you help me with this regex manipulation ...sorry but I'mno skilled about regex

Thanks in advance for your help :sweating:

AnyB.

Edited by anybastard

Share this post


Link to post
Share on other sites
careca

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 size

assign difference to a variable

write the variable to the file either by line

or the whole file with all variables in the middle

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites
anybastard

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,

Share this post


Link to post
Share on other sites
jdelaney

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 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.

Share this post


Link to post
Share on other sites
anybastard

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.

Share this post


Link to post
Share on other sites
somdcomputerguy

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.

Share this post


Link to post
Share on other sites
jdelaney

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.

Share this post


Link to post
Share on other sites
anybastard

Hi ...

sorry for my mistake :( I will try

Tnx

BRs

AnyB

Share this post


Link to post
Share on other sites
JLogan3o13

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)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
anybastard

Hello ,

lazyGuys ??? LOL I will change with noSkilledguys

In anyway thanks to all for your advice and code

BRs

AnyB

Share this post


Link to post
Share on other sites
anybastard

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

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
anybastard

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

Share this post


Link to post
Share on other sites
careca

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 by careca

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites
anybastard

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

Share this post


Link to post
Share on other sites
JLogan3o13

Glad you worked it out...


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
careca

Come back when you get stuck, and then, let us know what you have so far.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

Share this post


Link to post
Share on other sites
anybastard

Hi Careca ,

sure , I will do and thanks a lot for your suggestion, advice and.....code

BRs

An1B

Share this post


Link to post
Share on other sites
anybastard

Hello guys ,

always me ... I have again a little problem related to "my" script

The problem is on this line

shrink minimum=8704-----------------------------> Constant value 3

this part of the code is ok

If 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 step

Can you help me to solve this question , please ?

BRs

AnyB

Edited by anybastard

Share this post


Link to post
Share on other sites
somdcomputerguy

I think with these two functions you can get around however many characters make up the number.

StringMid StringInStr

I 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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×