Specific Header after every 30 records

Hi All,

I have got a requirement.
I have a source file, EMPFULL.txt and I need to split the data for every 30 records
and place a Typical Header as below with system and page number too.

2012.01.03                    Employee Dept  Report                             1
...################################################################################
...# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro
...#
...################################################################################
Record1
Record2
.
.
Record30
2012.01.03                    Employee Dept  Report                             2
...################################################################################
...# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro
...#
...################################################################################
Record31
Record32
.
.
Record60
2012.01.03                    Employee Dept  Report                             3
...################################################################################
...# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro
...#
...################################################################################
.
.
.
.
.
2012.01.03                    Employee Dept  Report                             n
...################################################################################
...# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro
...#
...################################################################################

Here the number of records in Source file is dynamic.
Please help in this.

Cheers,
SRK

Based on the input, can you display the desired output?

Sorry..

The above one in the code tag is the expected output.
Input file contains employee data say 10000 records, now we need to insert the header(above format with system date and page number) for every 30 records.

Thanks.

Yes......... And what does a "record" look like? :wall: Is it a line? Or is it a page? Or is it marked by some header and terminator lines? Or what?

If it's just lines, you can do this:

awk 'BEGIN { while(getline<"headerfile") H=H "\n" $0; }; (NR%30)==0 { print H } 1' data

Hi,
Here the records are lines only.
Input is

 
99991111 #S993980    #77786666 # Sample 11                          6
99991112 #S993980    #00000000 # Sample 6                           4
99996673 #S777660    #77786666 # Sample 11                          #
99996674 #S777660    #00000000 # Sample 6                           #
99999165 #S333660    #77786666 # Sample 11                          7
99999166 #S333660    #00000000 # Sample 6                           #
99990607 #S338740    #77786666 # Sample 11                          6
99990608 #S338740    #00000000 # Sample 6                           #
99011079 #S376680    #77786666 # Sample 11                          #
99011010 #S376680    #00000000 # Sample 6                           #
99990111 #S660970    #77786666 # Sample 11                          #
99990112 #S660970    #00000000 # Sample 6                           #
99990813 #S336910    #77786666 # Sample 11                          #
99990814 #S336910    #00000000 # Sample 6                           1
99013115 #S398460    #77786666 # Sample 11                          #
99013116 #S398460    #00000000 # Sample 6                           #
99993617 #S316990    #77786666 # Sample 11                          #
99993618 #S316990    #00000000 # Sample 6                           #
99996119 #Q046640    #77786666 # Sample 11                          #
99996120 #Q046640    #00000000 # Sample 6                           1
99990921 #S331840    #77786666 # Sample 11                          #
99990922 #S331840    #00000000 # Sample 6                           #
99991023 #Q077760    #77786666 # Sample 11                          #
99991024 #Q076001    #00000000 # Sample 6                           #
99991025 #S686390    #77786666 # Sample 11                          6
99991026 #S686390    #00000000 # Sample 6                           #
99991627 #S094370    #77786666 # Sample 11                          #
99991628 #S094370    #00000000 # Sample 6                           #
99998629 #S364690    #00000000 # Sample 6                           #
99996730 #S637380    #77786666 # Sample 11                          #
99991231 #S094372    #77786666 # Sample 11                          #
99991332 #S094373    #00000000 # Sample 6                           #
99998433 #S364694    #00000000 # Sample 6                           #
99996534 #S637385    #77786666 # Sample 11                          #

Output shall be

2012.01.03                    Employee Dept  Report                             1
�################################################################################
�# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro
�#
�################################################################################
99991111 #S993980    #77786666 # Sample 11                          6
99991112 #S993980    #00000000 # Sample 6                           4
99996673 #S777660    #77786666 # Sample 11                          #
99996674 #S777660    #00000000 # Sample 6                           #
99999165 #S333660    #77786666 # Sample 11                          7
99999166 #S333660    #00000000 # Sample 6                           #
99990607 #S338740    #77786666 # Sample 11                          6
99990608 #S338740    #00000000 # Sample 6                           #
99011079 #S376680    #77786666 # Sample 11                          #
99011010 #S376680    #00000000 # Sample 6                           #
99990111 #S660970    #77786666 # Sample 11                          #
99990112 #S660970    #00000000 # Sample 6                           #
99990813 #S336910    #77786666 # Sample 11                          #
99990814 #S336910    #00000000 # Sample 6                           1
99013115 #S398460    #77786666 # Sample 11                          #
99013116 #S398460    #00000000 # Sample 6                           #
99993617 #S316990    #77786666 # Sample 11                          #
99993618 #S316990    #00000000 # Sample 6                           #
99996119 #Q046640    #77786666 # Sample 11                          #
99996120 #Q046640    #00000000 # Sample 6                           1
99990921 #S331840    #77786666 # Sample 11                          #
99990922 #S331840    #00000000 # Sample 6                           #
99991023 #Q077760    #77786666 # Sample 11                          #
99991024 #Q076001    #00000000 # Sample 6                           #
99991025 #S686390    #77786666 # Sample 11                          6
99991026 #S686390    #00000000 # Sample 6                           #
99991627 #S094370    #77786666 # Sample 11                          #
99991628 #S094370    #00000000 # Sample 6                           #
99998629 #S364690    #00000000 # Sample 6                           #
99996730 #S637380    #77786666 # Sample 11                          #
2012.01.03                    Employee Dept  Report                             2
�################################################################################
�# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro
�#
�################################################################################
99991231 #S094372    #77786666 # Sample 11                          #
99991332 #S094373    #00000000 # Sample 6                           #
99998433 #S364694    #00000000 # Sample 6                           #
99996534 #S637385    #77786666 # Sample 11                          #

Here the number of lines(source records) may vary and thus the number of pages (group of 30 lines).
The final output shall include

  1. Header,System date and pagenumber for every 30 lines(page).

Appreciate your help in this.

Thanks in advance.
SRK.

DAY=$(date +%Y.%m.%d)
awk -v d=$DAY 'function Print_header()
                  { print d,"\t\t\tEmployee Dept  Report\t\t\t\t" ++i
                    print "...################################################################################"
                    print "...# EmpNo   #Id/Number  #Deptid #Departmetname                                #Pro"
                    print "...#"
                    print "...################################################################################"
                  }
               BEGIN{Print_header()}
               {print;if (FNR%30 == 0) Print_header()
               }' infile
1 Like

This is working fine.. Thanks rdcwayx:)

1 Like