1

This is a quite simple script I would assume but my bash skills are non-existent.

I have a file named file_name_01.txt and I need to generate a number N of files identical to this one (ie: duplicates) but changing the names so the endings are in ascending order. The resulting files will be named like so:

file_name_02.txt
file_name_03.txt
...
file_name_09.txt
file_name_10.txt
...
file_name_N.txt

How can I generate such a script?

1
  • 3
    What is the question and what have you done so far? Commented Dec 5, 2013 at 18:43

2 Answers 2

1

How about:

for i in {2..20}; do cp file_name_01.txt $(printf 'file_name_%02d.txt' $i); done

Replace "20" with whatever your N value is. That command is equivalent to:

cp file_name_01.txt file_name_02.txt
cp file_name_01.txt file_name_03.txt
cp file_name_01.txt file_name_04.txt
cp file_name_01.txt file_name_05.txt
cp file_name_01.txt file_name_06.txt
cp file_name_01.txt file_name_07.txt
cp file_name_01.txt file_name_08.txt
cp file_name_01.txt file_name_09.txt
cp file_name_01.txt file_name_10.txt
cp file_name_01.txt file_name_11.txt
cp file_name_01.txt file_name_12.txt
cp file_name_01.txt file_name_13.txt
cp file_name_01.txt file_name_14.txt
cp file_name_01.txt file_name_15.txt
cp file_name_01.txt file_name_16.txt
cp file_name_01.txt file_name_17.txt
cp file_name_01.txt file_name_18.txt
cp file_name_01.txt file_name_19.txt
cp file_name_01.txt file_name_20.txt
Sign up to request clarification or add additional context in comments.

1 Comment

Marking this one as accepted since I find it easier to read. Thanks!
1

Using xargs

printf "%s\0" file_name_{02..11}.txt | xargs -0 -L 1 -I {} cp file_name_01.txt {}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.