Question

this might be obvious, but I can't get it done: say there is a file called a1.xml and I want to create 7 additional copies named with sequential numbers (a2.xml, a3.xml). I tried to break the problem in different steps but still stuck. any thoughts?

thanks

Was it helpful?

Solution

You can do:

for f in a{2..7}.txt; do
    cp a1.xml "$f"
done

OTHER TIPS

Easiest:

for f in a2 a3 a4 a5 a6 a7
do cp a1.xml $f.xml
done

Also works (given command seq) — and better if you need 500 copies:

for n in $(seq 2 7)
do cp a1.xml a$n.xml
done

Or use arithmetic:

i=2
while [ $i -le 7 ]
do
    cp a1.xml a$i.xml
    ((i++))
done

Etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top