Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate text sequence in powershell

Tags:

powershell

I just had to produce a long xml sequence for some testing purpose, a lot of elements like <hour>2009.10.30.00</hour>.

This made me drop into a linux shell and just run

for day in $(seq -w 1 30) ; do  
  for hour in $(seq -w 0 23) ; 
    do echo "<hour>2009.10.$day.$hour</hour>" ; 
  done ; 
done >out

How would I do the same in powershell on windows ?

like image 465
Anonym Avatar asked Feb 11 '26 08:02

Anonym


1 Answers

Pretty similar...

$(foreach ($day in 1..30) {
    foreach ($hour in 0..23) {
        "<hour>2009.10.$day.$hour</hour>"
    }
}) > tmp.txt

Added file redirection. If you are familiar with bash the syntax should be pretty intuitive.

like image 51
Paolo Tedesco Avatar answered Feb 14 '26 17:02

Paolo Tedesco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!