-1

Считывает входной номер "n" и записывает 0 1 ... n на выход "n" раз, разделенных пробелами. Например: n = 3 1 2 3 1 2 3 1 2 3

Большое спасибо!

1 ответ1

1

Я уверен, что это можно улучшить, но у меня есть решение sed для однозначных чисел:

h; # put count in holding space
s/9/8 9/ # replace 9 with 8 9
s/8/7 8/ # and so on ...
s/7/6 7/ # ensuring that the pattern space
s/6/5 6/ # ends up as 1 ... n
s/5/4 5/
s/4/3 4/
s/3/2 3/
s/2/1 2/
p # print pattern space
x # exchange pattern and hold space
/9/{s/9/8/;x;p;x} # replace 9 with 8
/8/{s/8/7/;x;p;x} # and so on ...
/7/{s/7/6/;x;p;x} # effectively counting down
/6/{s/6/5/;x;p;x} # exchanging, printing and exchanging
/5/{s/5/4/;x;p;x} # each time
/4/{s/4/3/;x;p;x} # so that the pattern space
/3/{s/3/2/;x;p;x} # is printed n times
/2/{s/2/1/;x;p;x}
/1/d # we have reached one, we're done

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .