Jump to content
oemript

How to code it using Powershell Script?

Recommended Posts

oemript

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

Share this post


Link to post
Share on other sites
oemript

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

Share this post


Link to post
Share on other sites
JLogan3o13

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

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

Share this post


Link to post
Share on other sites
oemript

There is no option to delete post, could you please help to delete one of them?

Thank you very much

Share this post


Link to post
Share on other sites
Danyfirex

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

  • Like 1

Share this post


Link to post
Share on other sites
oemript
Posted (edited)
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

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

×