Jump to content

How to code it using Powershell Script?


oemript
 Share

Recommended Posts

Referring to following coding, I would like to know on how to use loop to repeat searching matched word until the end of file.
 

$Source = Get-Content 'C:\Source.txt'
$name = [regex]::match($Source, '"name":"(.*?)"').Groups[1].Value
Write-Host "$name"

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

C:\Source.txt contains following text

"name":"ABC" Go to School by Bus"name":"XYZ" Go to Library for reading

It should display following text

ABC

XYZ

Edited by oemript
Link to comment
Share on other sites

Referring to following coding, I would like to know on how to use loop to repeat searching matched word until the end of file.
 

$Source = Get-Content 'C:\Source.txt'
$name = [regex]::match($Source, '"name":"(.*?)"').Groups[1].Value
Write-Host "$name"

Does anyone have any suggestions?
Thanks in advance for any suggestions

 

C:\Source.txt contains following text

"name":"ABC" Go to School by Bus"name":"XYZ" Go to Library for reading

It should display following text

ABC

XYZ

Link to comment
Share on other sites

  • Moderators

Moved to a more appropriate sub-forum.

Edit: And Merged threads - you have been around long enough to know to stick to one post.

Edited by JLogan3o13

"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

You could do this.

 

$fileContent = [IO.File]::ReadAllText("C:\Users\You\Desktop\Test.txt")

$matches=[regex]::Matches($fileContent,'"name":"(.*?)"')


For ($i=0; $i -lt $matches.Count; $i++) {
  Write-Host $matches[$i].Groups[1].Value
}


Saludos

Link to comment
Share on other sites

  • 2 weeks later...
On 1/1/2018 at 0:57 AM, Danyfirex said:

You could do this.

 


$fileContent = [IO.File]::ReadAllText("C:\Users\You\Desktop\Test.txt")

$matches=[regex]::Matches($fileContent,'"name":"(.*?)"')


For ($i=0; $i -lt $matches.Count; $i++) {
  Write-Host $matches[$i].Groups[1].Value
}


Saludos

Thank you very much for suggestions (^v^)

I would like to know on how to set the matching condition in order to retrieve 1 year as return into $match as shown below

$matches=[regex]::Matches($fileContent,'????(.*?)????')

Given : skdk kjn kjd<div class="c-time__value">            1        </div>        <div class="c-time__unit">            year        </div> jkdhjfknkjkjd

Do you have any suggestions?
Thanks, to everyone very much for any suggestions (^v^)

 

 

Edited by oemript
Link to comment
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
 Share

  • Recently Browsing   0 members

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