Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

Header:

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

Footer:

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

How can I achieve this in Unix?

share|improve this question
    
What have you tried? –  jordanm Nov 2 '12 at 4:33
add comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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