Reputation:
I work on macOS High Sierra 10.13.3. My shell is bash.
When I type, echo {1,2}{3,4}
I get: 13 14 23 24
.
Is there an option to get 13 24
only?
I am interested in creating many files where two locations in a file vary together. For example, I want the files:
file1file1
file2file2
file3file3
It would be convenient to write something like file{1,2,3}file{1,2,3} option
instead of file1file1 file2file2 file3file3
.
I would like to be able to use this expansion in a command, such as:
touch file{1,2,3}file{1,2,3} option
to create three files.
I hope that the functionality I am looking for is clear.
Ultimately, the context I want to use this functionality in is with a snakemake command:
snakemake --cores 3 release{42,43,44}/file{42,43,44}.txt
where I want snakemake to produce the files release42/file42.txt, release43/file43.txt and release44/file44.txt.
If I use a loop to achieve this, the files will be produced in succession. However, by typing snakemake release42/file42.txt release43/file43.txt release44/file44.txt
, the three files will be produced simultaneously. However, as I am lazy, I want to type something shorter than snakemake release42/file42.txt release43/file43.txt release44/file44.txt
.
Upvotes: 4
Views: 156
Reputation: 67527
to get 13 14 do
$ echo 1{3,4}
for the duplicates, there are other ways
$ for i in {1..3}; do printf "file%dfile%d " $i $i; done
file1file1 file2file2 file3file3
to use with touch
$ for i in {1..3}; do touch "file${i}file${i}"; done
or, using all filenames at once
$ touch $(for i in {1..3}; do printf "file%dfile%d " $i $i; done)
Upvotes: 1
Reputation: 295679
Use a loop to form an array.
items=( )
for i in {42,43,44}; do
items+=( "release$i/file$i.txt" )
done
snakemake "${items[@]}"
This runs snakemake
only once, with all the files listed.
Upvotes: 2