2

For example, I want to start from the far right column, and once that reaches 5, continue the count from the second farthest column.

0.0.0.0
0.0.0.1
0.0.0.2
0.0.0.3
0.0.0.4
0.0.0.5
0.0.1.5
0.0.2.5
0.0.3.5
0.0.4.5
0.0.5.5
0.1.5.5
0.2.5.5
0.3.5.5
0.4.5.5
0.5.5.5
1.5.5.5
2.5.5.5
3.5.5.5
4.5.5.5
5.5.5.5

So far, I was thinking of using:

for i in $(seq 0 5); do echo "0.0.0.$i"; done

and once i == 5, then well set i=0, and move the echo to the third position.

5
  • @thanasisp Yes, the ending would remain to the max value it reached. The previous user did offer a printf that does work nicely, but I'm trying to get a seq to work Commented Dec 4, 2020 at 8:35
  • It's a different thing to print the combinations or permutations from what you describe here. edit your question and make the question clear, with a correct output. Commented Dec 4, 2020 at 8:38
  • @thanasisp I thought I made that quite clear by showing it ends of at 5.5.5.5 and not any values being changed Commented Dec 4, 2020 at 8:40
  • Shouldn't the title be changed in "...If one column is equal to 5, ..." ? Commented Dec 4, 2020 at 10:13
  • Does it have to be a shell script using seq, or are dedicated text-processing tools like awk also an option? Commented Dec 4, 2020 at 11:05

1 Answer 1

4

Using loop:

{
  for i in $(seq 0 5); do echo "0.0.0.$i"   ; done;
  for j in $(seq 1 5); do echo "0.0.$j.$i"  ; done;
  for k in $(seq 1 5); do echo "0.$k.$j.$i" ; done;
  for l in $(seq 1 5); do echo "$l.$k.$j.$i"; done;
}

Using awk and more flexible to increase the repeat time as well as adjustable number of fields from the single line input:

awk -F"." -v OFS="." -v repeat=5 '
{ print $0;
  for(c=NF; c>=1; c--){
      for (i=1; i<=repeat; i++) { $c=i ; print $0; };
  };
}' <<<'0.0.0.0'
3
  • Would it be possible to use seq four different times ? Commented Dec 4, 2020 at 8:20
  • 1
    Really nice awk script! Commented Dec 5, 2020 at 17:29
  • 1
    @EdMorton thank you, I'm happy hearing this from you who is expert in awk field : ) Commented Dec 5, 2020 at 17:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.