Creating Header & Trailer for bulk volume data file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating Header & Trailer for bulk volume data file
# 1  
Old 05-11-2010
Creating Header & Trailer for bulk volume data file

Hi all,

I have a requirement to create a Header &Trailer for a file which is having 20 millions of records.

If I use the following method, i think it will take more time.
Code:
cat "Header"> file1.txt
cat Data_File>>file1.txt
cat "Trailer">>file1.txt

since second CAT command has to read all the data(20M records) from file and has append into file1.txt.

Is there any better optimized method to create Header&Trailer through UNIX script for this kind of BULK volume data files.


-- Thanks
--Raam C.

Last edited by Scott; 05-11-2010 at 02:22 PM.. Reason: Code tags, please...
# 2  
Old 05-11-2010
In general, calling cat with just one argument is a useless use of cat. Instead of running cat 3 times, just do:
Code:
cat header datafile footer > file1.txt

That's a bit more optimized than your way.

Beyond that, no; there's no UNIX system call to insert data before other data in a file, and I don't know a system that does. Nor is there a faster form of read() than the general purpose one, why would anyone ever use the "slow" one?

If whatever's using these datafiles can accept input on stdin, you could generate them at runtime to avoid the extra reads and wasted storage:
Code:
cat header datafile footer | command


Last edited by Corona688; 05-11-2010 at 02:11 PM..
# 3  
Old 05-15-2010
my data file is having around 20 millions of records, it is a fixed width format file.
Now I want to create Header and trailer like this...

Code:
Hcurrentdate"                  "
data"                             "
data"                             "
T0000004"                      "

Header will start with letter 'H' followed by currentdate, followed by 20 spaces.
Then data records will come with same length
Trailer record will start with 'T', number of records in file(including header&trailer) in 10 length filed, followed by 20 spaces.

Please suggest me how to implement all this logic in script?

Thanks in advanvce...

--Raamc

Last edited by Scott; 05-16-2010 at 12:56 PM.. Reason: Code tags, please...
# 4  
Old 05-15-2010
try this..
Code:
awk 'BEGIN{print H'`date`'<put spaces here>}{1}END{print TNR<put spaces here>}' filename > newfile

# 5  
Old 05-16-2010
vidyadhar,

This is not working, giving the error as below

Code:
awk: illegal statement
 input record number 1, file 108Learn.sh
 source line number 1


Any other ideas?

Last edited by Scott; 05-16-2010 at 12:57 PM.. Reason: Code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Removing Header and Trailer record of a EBCDIC file

I have a EBCDIC multi layout file which has a header record which is 21 bytes, The Detail records are 2427 bytes long and the trailer record is 9 bytes long. Is there a command to remove the header as well as trailer record and read only the detail records while at the same time not altering... (1 Reply)
Discussion started by: abhilashnair
1 Replies

2. Shell Programming and Scripting

Split and add header and trailer from input file

I need to split the file based on pattern from position 34-37 while retaining the header and trailer records in each individual split file Also is it possible to output the TOM and PAT records in the same output file ? I need the output file names same as xyz_pattern_Datetimestamp.txt ... (23 Replies)
Discussion started by: techedipro
23 Replies

3. Shell Programming and Scripting

Verify the header and trailer in file

please see my requirement, I hope I am clear. (9 Replies)
Discussion started by: mirwasim
9 Replies

4. Shell Programming and Scripting

Script to validate file header and trailer

Hi, I need a script that validates a file header/detail/trailer. File layout is: Header - Rec_Type|File_name|File_Date Detail - Rec_Type|field1|field2|field3... Trailder - Rec_Type|File_name|File_Date|Record_count Sample Data: HDR|customer_data.dat|20120709... (7 Replies)
Discussion started by: ash_sh
7 Replies

5. Shell Programming and Scripting

Remove last few characters in a file but keeping Header and trailer intact

Hi All, I am trying write a simple command using AWK and SED to this but without any success. Here is what I am using: head -1 test1.txt>test2.txt|sed '1d;$d' test1.txt|awk '{print substr($0,0,(length($0)-2))}' >>test2.txt|tail -1 test1.txt>>test2.txt Input: Header 1234567 abcdefgh... (2 Replies)
Discussion started by: nvuradi
2 Replies

6. UNIX for Dummies Questions & Answers

Adding header and trailer into a file

Hi, I want to add the below Header to all the files in sequence File1,File2,File3...etc "ABC,<number of chracter in the file>" e,g - If File1 is as below pqrstuvdt abcdefgh then I want to add the above header into it ,So that File1 becomes as below ABC,17 pqrstuvdt abcdefgh ... (9 Replies)
Discussion started by: spari2
9 Replies

7. Shell Programming and Scripting

Adding Header and Trailer records to a appended file

How can we a shell script and pass date parameters .I have 3 files comming from Datastage with |" delimited I need append 3 files as above: File1: P0000|"47416954|"AU|"000|"INS|"0000|"|"20060601|"99991231|"|"|"|"|"01 File 2:... (2 Replies)
Discussion started by: e1994264
2 Replies

8. Shell Programming and Scripting

Removing Header & Trailer from a file

Hi All, I am karthik. I am new to this forum. I have one requirement. I have a file with header and footer. Header may be like HDR0001 or FILE20090110 (Assume it is unknown so far, but i am sure there is a header in the file) likewise file has the trailer too. I just... (7 Replies)
Discussion started by: karthi_gana
7 Replies

9. UNIX for Dummies Questions & Answers

Copy all the files with time stamp and remove header,trailer from file

All, I am new to unix and i have the following requirement. I have file(s) landing into input directory with timestamp, first i want to copy all these files into seperate directory then i want to rename these files without timestamp and also remove header,trailer from that file.. Could... (35 Replies)
Discussion started by: ksrams
35 Replies

10. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies
Login or Register to Ask a Question