powershell - How to see if the next line of a TXT file starts with a number -


I am using powershell to read in a TXT and make some arguments for it. The TXT is setup in a very specific format, but I only care about one line that starts with 6 or 4. The problem is that I do not know how to check the next line. I

  $ files = Get-ChildItem $ source *. Starting with $ $ File = Get-content $ files   

and then check for each line

  foreach ($ $ in file Line "StartsWith" ("6") {Write-Host "It starts with line 6"} elseif ($ line.StartsWith ("4")) {Write-host "This line 4 ") otherwise {($ line.StartsWith (" 4 ")) and (start with the next line 4)) {Write - Host" This line begins with 4 and starts with the next line 4 "}" And {write-host "does not start with line 6 or 4 I  $ line + 1  or  $ line [x + 1]  and even    

$ file [x + 1] but did not generate results from what I want because they will read in line and next next line can someone tell me how to check if the next $ line 4 starts

complete this what you need, the way I parse the text files Going $ file = Get-content $ files It seems ... by using the for loop we create a reference point $ i to look forward to the array in $ content Can be used

and the second part of the statement - (($ i + 1) -lt $ content.Count - ensures that You do not get OOB exception if you want to appear beyond the "edge" of the $ content array, i.e. looking at the last line ($ i = $ content.Count-1)

  $ files = Get-ChildItem $ source *. * Foreach ($ file in $ files) {$ content = Get-content $ for file ($ i = 0; $ i -lt $ content.Count; $ i ++) {$ Line = $ content [$ i] If the line ("$ 6") with line $. ("6") {Write-host "This line starts with 6"} elseif ($ line.StartsWith ("4")) {write-host "This line 4 ("$ line. StartsWith" ("4") and (($ i + 1) -lt $ content.Count) {$ nextLine = $ content [$ i + 1] if ( $ Next line. Start ("4") {Write-host "It starts with line 4 and starts with next line 4"}} and {write-host "starts with row 6 or 4The o occurs} "}}   

Hope this helps.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -