2

{txtfile,index}{1..3}.{txt,html}

I want {txtfile,index} to correspond with {txt,html}
to produce:
txtfile1.txt
txtfile2.txt
txtfile3.txt
index1.html
index2.html
index3.html

but this code will generate all possible combinations
I don't want txtfile1.html or index1.txt
so the below doesn't work..
{txtfile,index}{1..3}.{txt,html}

I just thought corresponding lists expansion would be nice (their use case is almost always coupled with brace expansion)
syntax could be : {txtfile:index}{1..3}.{txt:html}
since we only need this feature for lists of length 2 or more, there will always be : so we know it's a corresponding list

here is a very long solution using for loops and 3 lines..
note: this solution is unusable for fast manual file creation

fileNames=(txtfile index)
fileExtensions=(txt html)
for i in ${!fileNames[@]}; do echo ${fileNames[$i]}{1..3}.${fileExtensions[$i]}; done

one line for copy paste: fileNames=(txtfile index); fileExtensions=(txt html); for i in ${!fileNames[@]}; do echo ${fileNames[$i]}{1..3}.${fileExtensions[$i]}; done

even this is bad, it does 2 echo, so 2 lines.. (it still works if all I want to do it touch create files)

txtfile1.txt txtfile2.txt txtfile3.txt
index1.html index2.html index3.html
3

You're overengineering this:

txtfile{1..3}.txt index{1..3}.html

is what you need.

3

The list

txtfile1.txt
txtfile2.txt
txtfile3.txt
index1.html
index2.html
index3.html

may be generated using the following two brace expansions:

txtfile{1..3}.txt
index{1..3}.html

Example:

$ printf '%s\n' txtfile{1..3}.txt index{1..3}.html
txtfile1.txt
txtfile2.txt
txtfile3.txt
index1.html
index2.html
index3.html

You could possibly write that as the single brace expansion

{txtfile{1..3}.txt,index{1..3}.html}

but you don't gain anything from that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.