![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | are there tutorial on string processing with power-shell? I am new to power-shell and find it hard to follow. Are there step-by-step tutorial showing how to use it for string processing? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | RE: are there tutorial on string processing with power-shell? I don't know of a specific tutorial on string handling with PowerShell but what you can do is use PowerShell to help you learn. if you create a string variable and then put it through get-member you will see a list of the methods and properties for that string. $a = "abcdef" $a | get-member You can find information about the methods and properties here - http://msdn2.microsoft.com/en-us/lib...rs(vs.80).aspx If you have specific questions about string handling you can always post them on the forum Most of the PowerShell books that I've seen have something about using strings -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "light_wt" wrote: > I am new to power-shell and find it hard to follow. > > Are there step-by-step tutorial showing how to use it for string processing? > > Thanks. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: are there tutorial on string processing with power-shell? "light_wt" <lightwt@discussions.microsoft.com> wrote in message news:ADC309EF-BC30-4883-834F-2552556C6534@microsoft.com... >I am new to power-shell and find it hard to follow. > > Are there step-by-step tutorial showing how to use it for string > processing? > There are a number of books out on PowerShell. I really like WIndows PowerShell in Action. Perhaps you could ask your questions here and we'll attempt to answer them. Or is it the case that you don't know enough yet to know what questions to ask? BTW what exactly do you mean by string processing? Regex operations on strings, how to do variable substitution in a string, ... -- Keith |
My System Specs![]() |
| | #4 (permalink) |
| | Re: are there tutorial on string processing with power-shell? thanks keith and rich for jumping into it. I have several patterns that i like to parse. here is the first. A file with about 1000 lines of repeated patten which goes liked... ADD ... set ... DO ... execute ... ADD ... .. .. .. i want to break them up into multiple files where the block from "ADD to execute" will be in one file. thanks in advance for your couching. "Keith Hill [MVP]" wrote: > "light_wt" <lightwt@discussions.microsoft.com> wrote in message > news:ADC309EF-BC30-4883-834F-2552556C6534@microsoft.com... > >I am new to power-shell and find it hard to follow. > > > > Are there step-by-step tutorial showing how to use it for string > > processing? > > > > There are a number of books out on PowerShell. I really like WIndows > PowerShell in Action. Perhaps you could ask your questions here and we'll > attempt to answer them. Or is it the case that you don't know enough yet to > know what questions to ask? BTW what exactly do you mean by string > processing? Regex operations on strings, how to do variable substitution in > a string, ... > > -- > Keith > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: are there tutorial on string processing with power-shell? "light_wt" <lightwt@discussions.microsoft.com> wrote in message news:BAA301D0-EE37-484B-9FC1-2B5C03EB7D3D@microsoft.com... > thanks keith and rich for jumping into it. > > I have several patterns that i like to parse. > > here is the first. A file with about 1000 lines of repeated patten which > goes liked... > > ADD ... > set ... > DO ... > execute ... > > ADD ... > . > . > . > > > i want to break them up into multiple files where the block from "ADD to > execute" will be in one file. Try this: # Read file contents - this is created as array of strings $text = get-content c:\temp\data.txt # Join the array of strings into a single string, necessary # because we want to use a regex that spans lines $text = [string]::join("`n", $text) # Create a regex that uses singleline (. matches all) and # multiline (enhanced anchor mode) to search for # text between ^ADD and another ^ADD (or end of string). $regex = [regex]'(?sm)^ADD.*?(?=(^ADD|\Z))' # Use the System.Text.RegularExpressions.Regex.Matches static method $regex.Matches($text) | foreach {$i = 0}{$i++; $_.Value.Trim() > "foo${i}.txt"} -- Keith |
My System Specs![]() |
| | #6 (permalink) |
| | Re: are there tutorial on string processing with power-shell? this is cool, keith. what i like to do next is to create the filename based on a token in the ADD block, which is always after the 4thkeyword. That 4th keyword is RESERVE ADD 1stkeyword 2ndvar 3rdkeyword RESERVE UserSpecifiedFileName123 set ... DO ... execute ... ADD 1stkeyword 2ndvar 3rdkeyword RESERVE UserSpecifiedFileNameBBC .. .. .. So, would the code be something liked... $FileName=OneOfUserSpecifiedFileName $regex.Matches($text) | {$_.Value.Trim() > "$FileName.txt"} ??? |
My System Specs![]() |
| | #7 (permalink) |
| | Re: are there tutorial on string processing with power-shell? "light_wt" <lightwt@discussions.microsoft.com> wrote in message news:0BA87358-64E0-4DA1-88D1-E171E5FC0BC6@microsoft.com... > this is cool, keith. > So, would the code be something liked... > $FileName=OneOfUserSpecifiedFileName > $regex.Matches($text) | {$_.Value.Trim() > "$FileName.txt"} > ??? Needs to be a bit more like this: # Read file contents - this is created as array of strings $text = get-content c:\temp\data.txt # Join the array of strings into a single string, necessary # because we want to use a regex that spans lines $text = [string]::join("`n", $text) # Create a regex that uses singleline (. matches all) and # multiline (enhanced anchor mode) modes and searches for # text between ^ADD and another ^ADD (or end of string). $regex = [regex]'(?sm)^ADD.*?(?=(^ADD|\Z))' # Use the System.Text.RegularExpressions.Regex.Matches static method $regex.Matches($text) | foreach { $record = $_.Value.Trim(); if ($record -match '^ADD.*?RESERVE\s+(?<Filename>\w+)') { $filename = $matches.Filename + ".txt" $record > $filename } else { throw "Malformed record - can't find filename - $record" } } -- Keith |
My System Specs![]() |
| | #8 (permalink) |
| | Re: are there tutorial on string processing with power-shell? wow! i wish i am half as smart. how will i remove blocks of comment in the file? the style of comment use /* block of text */ |
My System Specs![]() |
| | #9 (permalink) |
| | Re: are there tutorial on string processing with power-shell? "light_wt" <lightwt@discussions.microsoft.com> wrote in message news:2D31F5C5-C877-4C4D-A6FE-828F21294048@microsoft.com... > wow! i wish i am half as smart. > > how will i remove blocks of comment in the file? the style of comment use > /* > block of text > */ Use something like this: $text -replace '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/', '' -- Keith |
My System Specs![]() |
| | #10 (permalink) |
| | Re: are there tutorial on string processing with power-shell? ding, ding, ding, ding, ding! you're the man. keith. can i buy you a beer, man? can you tell me something, else? if i want to ram up on regex, so, i don't have to post newbie questions like this. where can i learn it on my own? thanks, keith. "Keith Hill [MVP]" wrote: > "light_wt" <lightwt@discussions.microsoft.com> wrote in message > news:2D31F5C5-C877-4C4D-A6FE-828F21294048@microsoft.com... > > wow! i wish i am half as smart. > > > > how will i remove blocks of comment in the file? the style of comment use > > /* > > block of text > > */ > > Use something like this: > > $text -replace '/\*[^*]*\*+(?:[^/*][^*]*\*+)*/', '' > > -- > Keith > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| More processing power | General Discussion | |||
| Converting Get-ChildItems to string for processing. | PowerShell | |||
| end of line while processing a string token issue | PowerShell | |||
| Executing Power Shell Scripts from Windows Shell | PowerShell | |||
| Encountered end of line while processing a string token | PowerShell | |||