papinokoko
papinokoko

Reputation: 3

How to paste one file content in to different files using bash script?

I have a file with hundreds of names in it, ex:

Tokyo
New-York
Rio
Mexico

I want to create a empty file using the names of that list and latter apply/paste some text on it coming from another file.

So far I've done for f in $(cat list_of_names); do paste my text.txt > $f.nnn; done.

The idea is to generate a filename from the list like Tokyo.nnn (and many others) with the contents of text.txt

Tokyo.nnn will have a text with a configuration coming from text.txt. I expect to substitute $f with a name from the list while pasting the contents of text.txt on it.

Upvotes: 0

Views: 245

Answers (1)

Kishor Unnikrishnan
Kishor Unnikrishnan

Reputation: 2609

You can create empty file using xargs touch < list_of_names. And if you have a file named text.txt and need the its content in the files being created try this snippet.

while read filename; do
       cp -i sample "$filename".nnn
done < list_of_names

Upvotes: 1

Related Questions