I need to add a header and a footer to flat file - I just need to get values from the parameter like system date and report run date in the top line and for the footer I need to get the record count and prepend 00000 to it as shown below:


"A"  "F" "2012-03-01"    "20120229"


"$M" "0000001252"    "." "0000"

How can I achieve this in Unix?


You can put the header and footer in separate files and cat all together:

cat header original_file footer > new_file
mv new_file original_file

This command concatenates three files into one new file and the renames the file. If the header and footer are generated while running some programs you can do:

program_producing_header > new_file
cat original_file >> new_file
program_producing_footer >> new_file
mv new_file original_file

First this runs one or a series of commands which produce the header and writes them into new_file. If the file exists will be emptied first. The second line appends the contents of your original file to the new file and the next appends the output of your footer program. The last line renames the new file to the name of your original file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.