Generate text sequence in powershell

I just needed to create a long xml sequence for some testing purpose, lots of elements like <hour β†’ 2009.10.30.00 </ hour>.

It made me crawl into 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 can I do the same in powershell on windows?

+3
source share
2 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.

+3
source

, , , orsogufo . , - , :

1..30 | %{$day=$_;0..23} | %{"<hour>2009.10.$day.$_</hour>"} > tmp.txt
+3

Source: https://habr.com/ru/post/1725818/


All Articles