1

I want to create files Foo{A..Z} and insert "This is file [A-Z]" in the files.

Example:
FooG should contain the text
This is file G

First I need to create the files:
touch foo{A..Z}

Then I need to insert the text i want into all files:
echo This is file{A..Z} > foo{A..Z}

This won't quite work, as I need the current loop variable value
(which is somewhere between A and Z) from the foo{A..Z} from the line above.

1 Answer 1

5

No need to create the files first, just use a loop:

for i in {A..Z}; do
    echo "This is file $i" > "Foo$i"
done

Now $i can be used to refer to the letter to be inserted, as well as part of the filename.

Sign up to request clarification or add additional context in comments.

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.