read line by line and create new file

I would like to read line by line out of a file (one word per line) and create with each line a file.

The read line should be also pasted into the file with some other text.

Something like this:

cat readfile.txt | mkfile readline << "bla bli $readline blu"
awk '{print "blah bli" $0 "blu"}' readfile.txt > outfile.txt

This is how I would do it.

Thanks for your answer!

But it should create for each entry one file with the name of the entry.

Try this:

awk '{print "bla bli " $0 " blu" > $0}' readfile.txt

Regards

That works! Thaks!!

I have one more question:

instead of "bla bli " I would like to get several lines from a file and add it to $0

Can I do that?

Post an example of the files and the desired output.

Regards

I solved it like this:

#!/bin/bash

# Reads from one file all lines
# takes the first word as the name of a new file
# creates the new file with that name
# adds text out of a file before and after

output='/path/to/output/dir'
input='/path/to/input/file.txt'
prefix='/path/to/input/start.txt'
sufix='/path/to/input/end.txt'

cd $output

awk '{print "" > $0".java"}' $input

for i in $( ls ); do
  cat $prefix >> $i
done

awk '{print $0 >> $0".java"}' $input

for i in $( ls ); do
  cat $sufix >> $i
done

Any suggestions of improvement?