Apply brace expansion in “reverse order”Renaming a file to a shorter name easily using something like brace expansionBrace compressionBash Brace Expansion & VariablesExpand variable in brace expansionRight-to-left shell brace expansionPerform parameter expansion before brace expansion?bash combining wildcard expansion with brace expansionbackticks inside brace expansionNested brace expansion mystery in Bashbash in-line brace expansion

Does this Wild Magic result affect the sorcerer or just other creatures?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

Is a single radon-daughter atom in air a solid?

How is hair tissue mineral analysis performed?

What exactly is the 'online' in OLAP and OLTP?

Why use cross notes in sheet music for hip hop tracks?

Why tighten down in a criss-cross pattern?

What is the legal status of travelling with methadone in your carry-on?

Hot coffee brewing solutions for deep woods camping

Impossible darts scores

How do I turn off a repeating trade?

Why is it recommended to mix yogurt starter with a small amount of milk before adding to the entire batch?

Can any NP-Complete Problem be solved using at most polynomial space (but while using exponential time?)

Do I have any obligations to my PhD supervisor's requests after I have graduated?

Output of "$OSTYPE:6" on old releases of Mac OS X

Why don't countries like Japan just print more money?

What happens to Cessna electric flaps that are moving when power is lost?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

Minimum distance between holes in inner tube

How do I professionally let my manager know I'll quit over smoking in the office?

What is "industrial ethernet"?

Did the CIA blow up a Siberian pipeline in 1982?

Suggested order for Amazon Prime Doctor Who series

How much will studying magic in an academy cost?



Apply brace expansion in “reverse order”


Renaming a file to a shorter name easily using something like brace expansionBrace compressionBash Brace Expansion & VariablesExpand variable in brace expansionRight-to-left shell brace expansionPerform parameter expansion before brace expansion?bash combining wildcard expansion with brace expansionbackticks inside brace expansionNested brace expansion mystery in Bashbash in-line brace expansion






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















For example a..b1..3 expands to a1 a2 a3 b1 b2 b3.



If I wanted to print a1 b1 c1 a2 b2 c2 a3 b3 c3, is there an analogous way to do that? What's the simplest way?










share|improve this question






























    3















    For example a..b1..3 expands to a1 a2 a3 b1 b2 b3.



    If I wanted to print a1 b1 c1 a2 b2 c2 a3 b3 c3, is there an analogous way to do that? What's the simplest way?










    share|improve this question


























      3












      3








      3








      For example a..b1..3 expands to a1 a2 a3 b1 b2 b3.



      If I wanted to print a1 b1 c1 a2 b2 c2 a3 b3 c3, is there an analogous way to do that? What's the simplest way?










      share|improve this question
















      For example a..b1..3 expands to a1 a2 a3 b1 b2 b3.



      If I wanted to print a1 b1 c1 a2 b2 c2 a3 b3 c3, is there an analogous way to do that? What's the simplest way?







      bash brace-expansion






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 hours ago









      K7AAY

      2,08011029




      2,08011029










      asked 8 hours ago









      RUBEN GONÇALO MOROUÇORUBEN GONÇALO MOROUÇO

      434




      434




















          5 Answers
          5






          active

          oldest

          votes


















          4














          You could do:



          $ eval echo 'a..c'1..3
          a1 b1 c1 a2 b2 c2 a3 b3 c3


          Which then tells the shell to evaluate:



          echo a..c1 a..c2 a..c3





          share|improve this answer






























            1














            a..c1 a..c2 a..c3


            The brace expansions in a..c1..3 are expanded left to right, so you first get a1..3 b1..3 c1..3 and then the letters are combined with the numbers into a1 a2 a3 b1 b2 b3 c1 c2 c3. To get the order you want, you will have to use the slightly longer expression above.






            share|improve this answer























            • If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

              – RUBEN GONÇALO MOROUÇO
              8 hours ago






            • 1





              @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

              – Kusalananda
              8 hours ago



















            0














            For this particular case, I think that the option given by Stéphane Chazelas is the best one.



            On the other hand, when you expand more complex things, this option doesn't scale well. So, you can achieve the same with this:



            printf '%s' a..c1..3 | sort -zk 1.2,1.2 | tr '' ' '


            which returns:



            a1 b1 c1 a2 b2 c2 a3 b3 c3


            Seems a little messy, but now, I have a huge control in the order, just changing two chars in the command above; for example:



            echo a..b1..2a..b1..2


            this will expand to:



            a1a1 a1a2 a1b1 a1b2 a2a1 a2a2 a2b1 a2b2 b1a1 b1a2 b1b1 b1b2 b2a1 b2a2 b2b1 b2b2


            Suppose I want all the 1 in the second expansion, then the 2:



            printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.2 | tr '' ' '
            a1a1 a1a2 a1b1 a1b2 b1a1 b1a2 b1b1 b1b2 a2a1 a2a2 a2b1 a2b2 b2a1 b2a2 b2b1 b2b2


            Suppose I want all the a in the third expansion, then the b:



            printf '%s' a..b1..2a..b1..2 | sort -zk 1.3,1.3 | tr '' ' '
            a1a1 a1a2 a2a1 a2a2 b1a1 b1a2 b2a1 b2a2 a1b1 a1b2 a2b1 a2b2 b1b1 b1b2 b2b1 b2b2


            Suppose I want all the 1 in the fourth expansion, then the 2:



            printf '%s' a..b1..2a..b1..2 | sort -zk 1.4,1.4 | tr '' ' '
            a1a1 a1b1 a2a1 a2b1 b1a1 b1b1 b2a1 b2b1 a1a2 a1b2 a2a2 a2b2 b1a2 b1b2 b2a2 b2b2


            Suppose I want all the 1a in the middle, then 1b, then 2a, then 2b:



            printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.3 | tr '' ' '
            a1a1 a1a2 b1a1 b1a2 a1b1 a1b2 b1b1 b1b2 a2a1 a2a2 b2a1 b2a2 a2b1 a2b2 b2b1 b2b2


            You can even, just as easily, reverse any order in the expansions above, just adding and r to the previous command; for example, the last one:



            printf '%s' a..b1..2a..b1..2 | sort -rzk 1.2,1.3 | tr '' ' '
            b2b2 b2b1 a2b2 a2b1 b2a2 b2a1 a2a2 a2a1 b1b2 b1b1 a1b2 a1b1 b1a2 b1a1 a1a2 a1a1





            share|improve this answer






























              -1














              Using a loop:



              for l in a..b; do printf '%sn' "$l"1..3; done


              This will loop through your first expansion and then expand each character with the second.



              If you need the output all on one line you can remove the n:



              for l in a..b; do printf '%s ' "$l"1..3; done


              This won't give you a trailing newline but if you are passing it to a command or variable that shouldn't be an issue.






              share|improve this answer
































                -1














                bash, ksh, zsh



                A one liner that works in (bash, ksh, zsh) (not all shells can do "Brace expansion" in reverse order):



                $ echo 3..1c..a | rev
                a1 b1 c1 a2 b2 c2 a3 b3 c3


                An alternative that use eval (which still is for bash,ksh,zsh and may be more criptic) is:



                $ eval echo 'a..c'1..3
                a1 b1 c1 a2 b2 c2 a3 b3 c3


                To understand what happens, replace eval with echo:



                $ echo echo 'a..c'1..3
                echo a..c1 a..c2 a..c3


                The command executed (after eval expansion) is actually echo a..c1 a..c2 a..c3. Which expands as you want/need.



                all shells



                For all shells, use:



                $ for i in 1 2 3; do for j in a b c; do printf "%s%s " "$j" "$i"; done; done; echo
                a1 b1 c1 a2 b2 c2 a3 b3 c3


                If you don't mind a trailing space.

                If you must have no trailing space added:



                $ s=""; for i in 1 2 3; do for j in a b c; do printf "%s%s" "$s" "$j" "$i"; s=" "; done; done; echo
                a1 b1 c1 a2 b2 c2 a3 b3 c3





                share|improve this answer

























                  Your Answer








                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "106"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f525921%2fapply-brace-expansion-in-reverse-order%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  4














                  You could do:



                  $ eval echo 'a..c'1..3
                  a1 b1 c1 a2 b2 c2 a3 b3 c3


                  Which then tells the shell to evaluate:



                  echo a..c1 a..c2 a..c3





                  share|improve this answer



























                    4














                    You could do:



                    $ eval echo 'a..c'1..3
                    a1 b1 c1 a2 b2 c2 a3 b3 c3


                    Which then tells the shell to evaluate:



                    echo a..c1 a..c2 a..c3





                    share|improve this answer

























                      4












                      4








                      4







                      You could do:



                      $ eval echo 'a..c'1..3
                      a1 b1 c1 a2 b2 c2 a3 b3 c3


                      Which then tells the shell to evaluate:



                      echo a..c1 a..c2 a..c3





                      share|improve this answer













                      You could do:



                      $ eval echo 'a..c'1..3
                      a1 b1 c1 a2 b2 c2 a3 b3 c3


                      Which then tells the shell to evaluate:



                      echo a..c1 a..c2 a..c3






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 8 hours ago









                      Stéphane ChazelasStéphane Chazelas

                      322k57622987




                      322k57622987























                          1














                          a..c1 a..c2 a..c3


                          The brace expansions in a..c1..3 are expanded left to right, so you first get a1..3 b1..3 c1..3 and then the letters are combined with the numbers into a1 a2 a3 b1 b2 b3 c1 c2 c3. To get the order you want, you will have to use the slightly longer expression above.






                          share|improve this answer























                          • If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

                            – RUBEN GONÇALO MOROUÇO
                            8 hours ago






                          • 1





                            @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

                            – Kusalananda
                            8 hours ago
















                          1














                          a..c1 a..c2 a..c3


                          The brace expansions in a..c1..3 are expanded left to right, so you first get a1..3 b1..3 c1..3 and then the letters are combined with the numbers into a1 a2 a3 b1 b2 b3 c1 c2 c3. To get the order you want, you will have to use the slightly longer expression above.






                          share|improve this answer























                          • If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

                            – RUBEN GONÇALO MOROUÇO
                            8 hours ago






                          • 1





                            @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

                            – Kusalananda
                            8 hours ago














                          1












                          1








                          1







                          a..c1 a..c2 a..c3


                          The brace expansions in a..c1..3 are expanded left to right, so you first get a1..3 b1..3 c1..3 and then the letters are combined with the numbers into a1 a2 a3 b1 b2 b3 c1 c2 c3. To get the order you want, you will have to use the slightly longer expression above.






                          share|improve this answer













                          a..c1 a..c2 a..c3


                          The brace expansions in a..c1..3 are expanded left to right, so you first get a1..3 b1..3 c1..3 and then the letters are combined with the numbers into a1 a2 a3 b1 b2 b3 c1 c2 c3. To get the order you want, you will have to use the slightly longer expression above.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 8 hours ago









                          KusalanandaKusalananda

                          152k18298478




                          152k18298478












                          • If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

                            – RUBEN GONÇALO MOROUÇO
                            8 hours ago






                          • 1





                            @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

                            – Kusalananda
                            8 hours ago


















                          • If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

                            – RUBEN GONÇALO MOROUÇO
                            8 hours ago






                          • 1





                            @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

                            – Kusalananda
                            8 hours ago

















                          If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

                          – RUBEN GONÇALO MOROUÇO
                          8 hours ago





                          If you wanted to do it for a large range of "numbers" it wouldn't be practical anymore.

                          – RUBEN GONÇALO MOROUÇO
                          8 hours ago




                          1




                          1





                          @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

                          – Kusalananda
                          8 hours ago






                          @RUBENGONÇALOMOROUÇO No it wouldn't, and if you are doing it for a large range of numbers, I would suggest using an alternative approach, like a double loop. That would work for many thousands of combinations, whereas a brace expansions my trigger "argument list too long" in certain contexts.

                          – Kusalananda
                          8 hours ago












                          0














                          For this particular case, I think that the option given by Stéphane Chazelas is the best one.



                          On the other hand, when you expand more complex things, this option doesn't scale well. So, you can achieve the same with this:



                          printf '%s' a..c1..3 | sort -zk 1.2,1.2 | tr '' ' '


                          which returns:



                          a1 b1 c1 a2 b2 c2 a3 b3 c3


                          Seems a little messy, but now, I have a huge control in the order, just changing two chars in the command above; for example:



                          echo a..b1..2a..b1..2


                          this will expand to:



                          a1a1 a1a2 a1b1 a1b2 a2a1 a2a2 a2b1 a2b2 b1a1 b1a2 b1b1 b1b2 b2a1 b2a2 b2b1 b2b2


                          Suppose I want all the 1 in the second expansion, then the 2:



                          printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.2 | tr '' ' '
                          a1a1 a1a2 a1b1 a1b2 b1a1 b1a2 b1b1 b1b2 a2a1 a2a2 a2b1 a2b2 b2a1 b2a2 b2b1 b2b2


                          Suppose I want all the a in the third expansion, then the b:



                          printf '%s' a..b1..2a..b1..2 | sort -zk 1.3,1.3 | tr '' ' '
                          a1a1 a1a2 a2a1 a2a2 b1a1 b1a2 b2a1 b2a2 a1b1 a1b2 a2b1 a2b2 b1b1 b1b2 b2b1 b2b2


                          Suppose I want all the 1 in the fourth expansion, then the 2:



                          printf '%s' a..b1..2a..b1..2 | sort -zk 1.4,1.4 | tr '' ' '
                          a1a1 a1b1 a2a1 a2b1 b1a1 b1b1 b2a1 b2b1 a1a2 a1b2 a2a2 a2b2 b1a2 b1b2 b2a2 b2b2


                          Suppose I want all the 1a in the middle, then 1b, then 2a, then 2b:



                          printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.3 | tr '' ' '
                          a1a1 a1a2 b1a1 b1a2 a1b1 a1b2 b1b1 b1b2 a2a1 a2a2 b2a1 b2a2 a2b1 a2b2 b2b1 b2b2


                          You can even, just as easily, reverse any order in the expansions above, just adding and r to the previous command; for example, the last one:



                          printf '%s' a..b1..2a..b1..2 | sort -rzk 1.2,1.3 | tr '' ' '
                          b2b2 b2b1 a2b2 a2b1 b2a2 b2a1 a2a2 a2a1 b1b2 b1b1 a1b2 a1b1 b1a2 b1a1 a1a2 a1a1





                          share|improve this answer



























                            0














                            For this particular case, I think that the option given by Stéphane Chazelas is the best one.



                            On the other hand, when you expand more complex things, this option doesn't scale well. So, you can achieve the same with this:



                            printf '%s' a..c1..3 | sort -zk 1.2,1.2 | tr '' ' '


                            which returns:



                            a1 b1 c1 a2 b2 c2 a3 b3 c3


                            Seems a little messy, but now, I have a huge control in the order, just changing two chars in the command above; for example:



                            echo a..b1..2a..b1..2


                            this will expand to:



                            a1a1 a1a2 a1b1 a1b2 a2a1 a2a2 a2b1 a2b2 b1a1 b1a2 b1b1 b1b2 b2a1 b2a2 b2b1 b2b2


                            Suppose I want all the 1 in the second expansion, then the 2:



                            printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.2 | tr '' ' '
                            a1a1 a1a2 a1b1 a1b2 b1a1 b1a2 b1b1 b1b2 a2a1 a2a2 a2b1 a2b2 b2a1 b2a2 b2b1 b2b2


                            Suppose I want all the a in the third expansion, then the b:



                            printf '%s' a..b1..2a..b1..2 | sort -zk 1.3,1.3 | tr '' ' '
                            a1a1 a1a2 a2a1 a2a2 b1a1 b1a2 b2a1 b2a2 a1b1 a1b2 a2b1 a2b2 b1b1 b1b2 b2b1 b2b2


                            Suppose I want all the 1 in the fourth expansion, then the 2:



                            printf '%s' a..b1..2a..b1..2 | sort -zk 1.4,1.4 | tr '' ' '
                            a1a1 a1b1 a2a1 a2b1 b1a1 b1b1 b2a1 b2b1 a1a2 a1b2 a2a2 a2b2 b1a2 b1b2 b2a2 b2b2


                            Suppose I want all the 1a in the middle, then 1b, then 2a, then 2b:



                            printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.3 | tr '' ' '
                            a1a1 a1a2 b1a1 b1a2 a1b1 a1b2 b1b1 b1b2 a2a1 a2a2 b2a1 b2a2 a2b1 a2b2 b2b1 b2b2


                            You can even, just as easily, reverse any order in the expansions above, just adding and r to the previous command; for example, the last one:



                            printf '%s' a..b1..2a..b1..2 | sort -rzk 1.2,1.3 | tr '' ' '
                            b2b2 b2b1 a2b2 a2b1 b2a2 b2a1 a2a2 a2a1 b1b2 b1b1 a1b2 a1b1 b1a2 b1a1 a1a2 a1a1





                            share|improve this answer

























                              0












                              0








                              0







                              For this particular case, I think that the option given by Stéphane Chazelas is the best one.



                              On the other hand, when you expand more complex things, this option doesn't scale well. So, you can achieve the same with this:



                              printf '%s' a..c1..3 | sort -zk 1.2,1.2 | tr '' ' '


                              which returns:



                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                              Seems a little messy, but now, I have a huge control in the order, just changing two chars in the command above; for example:



                              echo a..b1..2a..b1..2


                              this will expand to:



                              a1a1 a1a2 a1b1 a1b2 a2a1 a2a2 a2b1 a2b2 b1a1 b1a2 b1b1 b1b2 b2a1 b2a2 b2b1 b2b2


                              Suppose I want all the 1 in the second expansion, then the 2:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.2 | tr '' ' '
                              a1a1 a1a2 a1b1 a1b2 b1a1 b1a2 b1b1 b1b2 a2a1 a2a2 a2b1 a2b2 b2a1 b2a2 b2b1 b2b2


                              Suppose I want all the a in the third expansion, then the b:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.3,1.3 | tr '' ' '
                              a1a1 a1a2 a2a1 a2a2 b1a1 b1a2 b2a1 b2a2 a1b1 a1b2 a2b1 a2b2 b1b1 b1b2 b2b1 b2b2


                              Suppose I want all the 1 in the fourth expansion, then the 2:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.4,1.4 | tr '' ' '
                              a1a1 a1b1 a2a1 a2b1 b1a1 b1b1 b2a1 b2b1 a1a2 a1b2 a2a2 a2b2 b1a2 b1b2 b2a2 b2b2


                              Suppose I want all the 1a in the middle, then 1b, then 2a, then 2b:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.3 | tr '' ' '
                              a1a1 a1a2 b1a1 b1a2 a1b1 a1b2 b1b1 b1b2 a2a1 a2a2 b2a1 b2a2 a2b1 a2b2 b2b1 b2b2


                              You can even, just as easily, reverse any order in the expansions above, just adding and r to the previous command; for example, the last one:



                              printf '%s' a..b1..2a..b1..2 | sort -rzk 1.2,1.3 | tr '' ' '
                              b2b2 b2b1 a2b2 a2b1 b2a2 b2a1 a2a2 a2a1 b1b2 b1b1 a1b2 a1b1 b1a2 b1a1 a1a2 a1a1





                              share|improve this answer













                              For this particular case, I think that the option given by Stéphane Chazelas is the best one.



                              On the other hand, when you expand more complex things, this option doesn't scale well. So, you can achieve the same with this:



                              printf '%s' a..c1..3 | sort -zk 1.2,1.2 | tr '' ' '


                              which returns:



                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                              Seems a little messy, but now, I have a huge control in the order, just changing two chars in the command above; for example:



                              echo a..b1..2a..b1..2


                              this will expand to:



                              a1a1 a1a2 a1b1 a1b2 a2a1 a2a2 a2b1 a2b2 b1a1 b1a2 b1b1 b1b2 b2a1 b2a2 b2b1 b2b2


                              Suppose I want all the 1 in the second expansion, then the 2:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.2 | tr '' ' '
                              a1a1 a1a2 a1b1 a1b2 b1a1 b1a2 b1b1 b1b2 a2a1 a2a2 a2b1 a2b2 b2a1 b2a2 b2b1 b2b2


                              Suppose I want all the a in the third expansion, then the b:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.3,1.3 | tr '' ' '
                              a1a1 a1a2 a2a1 a2a2 b1a1 b1a2 b2a1 b2a2 a1b1 a1b2 a2b1 a2b2 b1b1 b1b2 b2b1 b2b2


                              Suppose I want all the 1 in the fourth expansion, then the 2:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.4,1.4 | tr '' ' '
                              a1a1 a1b1 a2a1 a2b1 b1a1 b1b1 b2a1 b2b1 a1a2 a1b2 a2a2 a2b2 b1a2 b1b2 b2a2 b2b2


                              Suppose I want all the 1a in the middle, then 1b, then 2a, then 2b:



                              printf '%s' a..b1..2a..b1..2 | sort -zk 1.2,1.3 | tr '' ' '
                              a1a1 a1a2 b1a1 b1a2 a1b1 a1b2 b1b1 b1b2 a2a1 a2a2 b2a1 b2a2 a2b1 a2b2 b2b1 b2b2


                              You can even, just as easily, reverse any order in the expansions above, just adding and r to the previous command; for example, the last one:



                              printf '%s' a..b1..2a..b1..2 | sort -rzk 1.2,1.3 | tr '' ' '
                              b2b2 b2b1 a2b2 a2b1 b2a2 b2a1 a2a2 a2a1 b1b2 b1b1 a1b2 a1b1 b1a2 b1a1 a1a2 a1a1






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 5 hours ago









                              matsib.devmatsib.dev

                              47636




                              47636





















                                  -1














                                  Using a loop:



                                  for l in a..b; do printf '%sn' "$l"1..3; done


                                  This will loop through your first expansion and then expand each character with the second.



                                  If you need the output all on one line you can remove the n:



                                  for l in a..b; do printf '%s ' "$l"1..3; done


                                  This won't give you a trailing newline but if you are passing it to a command or variable that shouldn't be an issue.






                                  share|improve this answer





























                                    -1














                                    Using a loop:



                                    for l in a..b; do printf '%sn' "$l"1..3; done


                                    This will loop through your first expansion and then expand each character with the second.



                                    If you need the output all on one line you can remove the n:



                                    for l in a..b; do printf '%s ' "$l"1..3; done


                                    This won't give you a trailing newline but if you are passing it to a command or variable that shouldn't be an issue.






                                    share|improve this answer



























                                      -1












                                      -1








                                      -1







                                      Using a loop:



                                      for l in a..b; do printf '%sn' "$l"1..3; done


                                      This will loop through your first expansion and then expand each character with the second.



                                      If you need the output all on one line you can remove the n:



                                      for l in a..b; do printf '%s ' "$l"1..3; done


                                      This won't give you a trailing newline but if you are passing it to a command or variable that shouldn't be an issue.






                                      share|improve this answer















                                      Using a loop:



                                      for l in a..b; do printf '%sn' "$l"1..3; done


                                      This will loop through your first expansion and then expand each character with the second.



                                      If you need the output all on one line you can remove the n:



                                      for l in a..b; do printf '%s ' "$l"1..3; done


                                      This won't give you a trailing newline but if you are passing it to a command or variable that shouldn't be an issue.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 7 hours ago

























                                      answered 8 hours ago









                                      Jesse_bJesse_b

                                      16.9k34183




                                      16.9k34183





















                                          -1














                                          bash, ksh, zsh



                                          A one liner that works in (bash, ksh, zsh) (not all shells can do "Brace expansion" in reverse order):



                                          $ echo 3..1c..a | rev
                                          a1 b1 c1 a2 b2 c2 a3 b3 c3


                                          An alternative that use eval (which still is for bash,ksh,zsh and may be more criptic) is:



                                          $ eval echo 'a..c'1..3
                                          a1 b1 c1 a2 b2 c2 a3 b3 c3


                                          To understand what happens, replace eval with echo:



                                          $ echo echo 'a..c'1..3
                                          echo a..c1 a..c2 a..c3


                                          The command executed (after eval expansion) is actually echo a..c1 a..c2 a..c3. Which expands as you want/need.



                                          all shells



                                          For all shells, use:



                                          $ for i in 1 2 3; do for j in a b c; do printf "%s%s " "$j" "$i"; done; done; echo
                                          a1 b1 c1 a2 b2 c2 a3 b3 c3


                                          If you don't mind a trailing space.

                                          If you must have no trailing space added:



                                          $ s=""; for i in 1 2 3; do for j in a b c; do printf "%s%s" "$s" "$j" "$i"; s=" "; done; done; echo
                                          a1 b1 c1 a2 b2 c2 a3 b3 c3





                                          share|improve this answer



























                                            -1














                                            bash, ksh, zsh



                                            A one liner that works in (bash, ksh, zsh) (not all shells can do "Brace expansion" in reverse order):



                                            $ echo 3..1c..a | rev
                                            a1 b1 c1 a2 b2 c2 a3 b3 c3


                                            An alternative that use eval (which still is for bash,ksh,zsh and may be more criptic) is:



                                            $ eval echo 'a..c'1..3
                                            a1 b1 c1 a2 b2 c2 a3 b3 c3


                                            To understand what happens, replace eval with echo:



                                            $ echo echo 'a..c'1..3
                                            echo a..c1 a..c2 a..c3


                                            The command executed (after eval expansion) is actually echo a..c1 a..c2 a..c3. Which expands as you want/need.



                                            all shells



                                            For all shells, use:



                                            $ for i in 1 2 3; do for j in a b c; do printf "%s%s " "$j" "$i"; done; done; echo
                                            a1 b1 c1 a2 b2 c2 a3 b3 c3


                                            If you don't mind a trailing space.

                                            If you must have no trailing space added:



                                            $ s=""; for i in 1 2 3; do for j in a b c; do printf "%s%s" "$s" "$j" "$i"; s=" "; done; done; echo
                                            a1 b1 c1 a2 b2 c2 a3 b3 c3





                                            share|improve this answer

























                                              -1












                                              -1








                                              -1







                                              bash, ksh, zsh



                                              A one liner that works in (bash, ksh, zsh) (not all shells can do "Brace expansion" in reverse order):



                                              $ echo 3..1c..a | rev
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                                              An alternative that use eval (which still is for bash,ksh,zsh and may be more criptic) is:



                                              $ eval echo 'a..c'1..3
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                                              To understand what happens, replace eval with echo:



                                              $ echo echo 'a..c'1..3
                                              echo a..c1 a..c2 a..c3


                                              The command executed (after eval expansion) is actually echo a..c1 a..c2 a..c3. Which expands as you want/need.



                                              all shells



                                              For all shells, use:



                                              $ for i in 1 2 3; do for j in a b c; do printf "%s%s " "$j" "$i"; done; done; echo
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                                              If you don't mind a trailing space.

                                              If you must have no trailing space added:



                                              $ s=""; for i in 1 2 3; do for j in a b c; do printf "%s%s" "$s" "$j" "$i"; s=" "; done; done; echo
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3





                                              share|improve this answer













                                              bash, ksh, zsh



                                              A one liner that works in (bash, ksh, zsh) (not all shells can do "Brace expansion" in reverse order):



                                              $ echo 3..1c..a | rev
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                                              An alternative that use eval (which still is for bash,ksh,zsh and may be more criptic) is:



                                              $ eval echo 'a..c'1..3
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                                              To understand what happens, replace eval with echo:



                                              $ echo echo 'a..c'1..3
                                              echo a..c1 a..c2 a..c3


                                              The command executed (after eval expansion) is actually echo a..c1 a..c2 a..c3. Which expands as you want/need.



                                              all shells



                                              For all shells, use:



                                              $ for i in 1 2 3; do for j in a b c; do printf "%s%s " "$j" "$i"; done; done; echo
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3


                                              If you don't mind a trailing space.

                                              If you must have no trailing space added:



                                              $ s=""; for i in 1 2 3; do for j in a b c; do printf "%s%s" "$s" "$j" "$i"; s=" "; done; done; echo
                                              a1 b1 c1 a2 b2 c2 a3 b3 c3






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered 7 hours ago









                                              IsaacIsaac

                                              13.3k12159




                                              13.3k12159



























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f525921%2fapply-brace-expansion-in-reverse-order%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                                  Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                                  Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367