filling in strings in a template file using awk

Hi all,

I have a template form to fill in for quite a number of files and I want to automate the filling-in process. the concept seemed to be simple but i cant get it work. the template form is a text file containing the information below:

File Name:
Date Created:
Contents:

I need to fill in the File Name section and so if I read the individual files, it will insert the corresponding information to the template. my desired output will be something like:

if i read file1.xyz, it will generate a form named file1.txt containing the information:

File Name: file1.xyz
Date Created:
Contents:

and so on..

Many thanks in advance.

What OS are you running, what shell?

Please show the output of these two commands:

uname -a
echo $SHELL

Hi jim, these are the output of the two commands:

Linux irene-desktop 2.6.32-39-generic #86-Ubuntu SMP Mon Feb 13 21:47:32 UTC 2012 i686 GNU/Linux

/bin/bash

Many thanks.

 
for i in *.txt ; 
do 
 echo "File Name: $i" >> File.tmp 
 echo "File Modified Time : $(ls -l $i | awk '{print $6,$7,$8}')" >> File.tmp
 echo "Contents : "$(cat $i)"" >> File.tmp
 echo "" >> File.tmp
done
1 Like

Thanks much, :slight_smile: