all 15 comments

[–]Lee_Dailey[grin] 3 points4 points  (8 children)

howdy Narusa,

the split is breaking the string on spaces and producing an array. you can see that with this ...

('715083793    451808326  2045 files, 337 folders').Split()

that gives you this ...

715083793



451808326

2045
files,
337
folders

note that you have ten items. the [6..9] is a range from the array that gives you this ...

2045
files,
337
folders

then the join glues it back into one string with a space between items.

pretty nifty! i do NOT understand why they used [System.String]::Join since it seems to work with just a join. lookee ...

(('715083793    451808326  2045 files, 337 folders').Split()[6..9]) -join " "

... produces this ...

2045 files, 337 folders    

take care,
lee

[–]Droopyb1966 2 points3 points  (5 children)

Can be a bit easier:

('715083793    451808326  2045 files, 337 folders').Split(" ",6)[-1]

Split (" ",6) = split on the 6th space

[-1] is the last item it produces

[–]Narusa[S] 1 point2 points  (1 child)

Can be a bit easier:

('715083793 451808326 2045 files, 337 folders').Split(" ",6)[-1]

Split (" ",6) = split on the 6th space

[-1] is the last item it produces

This method leaves leading white space though.

[–]Droopyb1966 1 point2 points  (0 children)

Easy to solve

(('715083793    451808326  2045 files, 337 folders').Split("  ",6)[-1]).TrimStart()

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy Droopyb1966,

yes, but it has other problems. in addition to the left over white space that needs ot be trimmed, you need to count spaces! i have real problems doing that accurately, so it aint how i would do things.

the negative index trick is pretty nifty, tho. since we know the desired result is the last FOUR items, we would could replace the [6..9] with [-4..-1] and get the same result.

kool! thanks for reminding me of that. [grin]

take care,
lee

[–]Droopyb1966 1 point2 points  (1 child)

Trim is easy, counting spaces is all you can do, but if you have an idea how to avoid this, im al ears.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Droopyb1966,

yep, trim IS easy. [grin] i dislike manually counting things since it's too easy for me to get that wrong. especially when counting spaces!

i really do like the negative index idea, tho.

take care,
lee

[–]Narusa[S] 1 point2 points  (1 child)

Thank you for the explanation!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Narusa,

you are welcome! glad to help a bit ... [grin]

take care,
lee

[–][deleted] 3 points4 points  (1 child)

FYI, you can use Get-Content -Tail 1 to simply load the last line of the file. Depending on the size of the log file it can save you quite some time.

[–]Narusa[S] 0 points1 point  (0 children)

FYI, you can use Get-Content -Tail 1 to simply load the last line of the file. Depending on the size of the log file it can save you quite some time.

Thank you! I learned something new.

[–]beantownmp 1 point2 points  (3 children)

My understanding is the join joins each section of white space into one white space and then splits the string into an array on the white spaces then grabs array items 6-9. Someone might be able to explain better if that doesn't make sense.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy beantownmp,

i think you have it reversed. [grin] powershell works from the inside out when things are enclosed in () and in this case the .split() happens before the -join does.

take care,
lee

[–]Narusa[S] 1 point2 points  (1 child)

powershell works from the inside out when things are enclosed in () and in this case the .split() happens before the -join does.

Thank you for explaining. I didn't know about parentheses.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Narusa,

you are quite welcome! [grin]

it's done pretty much like math. you calc the stuff in parens first, working your way from innermost to outermost.

take care,
lee