[SOLVED] Multiple Text Files From A List

Hi Everyone!
I’m looking for a way to create multiple text files from words list i.e,

A list like:

  • Cats
  • Dogs
  • Rabbits
  • Etc.

In to:

  • Cats.txt
  • Dogs.txt
  • Rabbits.txt
  • Etc.txt

Is there any easy way to do so?

Using python, Yes.

Save this snippet in a file

li=['cat','dog','lion']
for i in li:
    open(i+'.txt','a').close()
    print('Creating {}.txt'.format(i))

Change the names in the list ‘li’ and run the program.
Text files will be created in the same directory.

3 Likes

In Bash, you can do this…

name=("apple" "cow" "banana")
for i in "${name[@]}"
do
    touch $i.txt
done

2 Likes

Many Thanks, It just work like a charm.

Many Thanks Mahesh, It’s working solution as well.