Specific Header after every 30 records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Specific Header after every 30 records
# 1  
Old 01-23-2012
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.
Code:
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
# 2  
Old 01-23-2012
Based on the input, can you display the desired output?
# 3  
Old 01-23-2012
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.
# 4  
Old 01-23-2012
Yes......... And what does a "record" look like? Smilie 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:

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

# 5  
Old 01-30-2012
Hi,
Here the records are lines only.
Input is
Code:
 
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
Code:
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.
# 6  
Old 01-30-2012
Code:
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

This User Gave Thanks to rdcwayx For This Post:
# 7  
Old 01-30-2012
This is working fine.. Thanks rdcwayxSmilie
This User Gave Thanks to srk409 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help in printing records where there is a 'header' in the first record ???

Hi, I have a backup report that unfortunately has some kind of hanging indent thing where the first line contains one column more than the others I managed to get the output that I wanted using awk, but just wanting to know if there is short way of doing it using the same awk Below is what... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Prefix a variable in the first column of all the records of the files with and without header

In a bash shell, I have to prefix a variable to two .CSV files File1.CSV and File2.CSV. One of the files has a header and the other one is with no header in the below format: "value11","value12","value13","value14","value15","value16" "value21","value22","value23","value24","value25","value26"... (7 Replies)
Discussion started by: dhruuv369
7 Replies

3. Shell Programming and Scripting

Copy header values into records

I'm using a shell script to manipulate a data file. I have a large file with two sets of data samples (tracking memory consumption) taken over a long period of time, so I have many samples. The problem is that all the data is in the same file so that each sample contains two sets of data.... (2 Replies)
Discussion started by: abercrom
2 Replies

4. 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

5. UNIX for Dummies Questions & Answers

pull date from header and append to all records

I did some searches, but couldn't really find what I'm looking for. I have a file formatted as below: BOF ABC CO - XYZ COMM DATA OF 07/05/2011 EBA00000001 sdfa rtyus uyml EBB00000001 54682 984w3 EBA00000002 mkiyuasdf 98234 I want to pull the date from the header record and add it... (4 Replies)
Discussion started by: keeferb
4 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. Shell Programming and Scripting

improve performance - replace $\| with $#@ and remove header and trailer records

Hi All, In my file i need to remove header and trailer records which comes in 1st line and last line respectively. After that i need to replace '$\|' with '$#@'. I am using sed command for this and its taking lot of time. Is there any other command which can be used to improve performance? ... (1 Reply)
Discussion started by: HemaV
1 Replies

8. Shell Programming and Scripting

Renaming all header to specific header pattern

Input #HAC0253 EFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #BASFS12 EFVEFVHIJEFVEFVTOPKEFVOPKTHIJTTHIJOPK #ACG5115 TEFVEFVOIJEFVHIJHIJOPKOPKHIJHIJTTEFVEFVOPKTTEFVEFVOPKHIJOPKOPKOPK #ECG5114 IJTOPKHIJEFVOEFVEFVOPKTTEFVEFVOPKHIJOPKOPKOPK . . Output (5 Replies)
Discussion started by: patrick87
5 Replies

9. 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

10. UNIX for Dummies Questions & Answers

How to extract duplicate records with associated header record

All, I have a task to search through several hundred files and extract duplicate detail records and keep them grouped with their header record. If no duplicate detail record exists, don't pull the header. For example, an input file could look like this: input.txt HA D1 D2 D2 D3 D4 D4... (17 Replies)
Discussion started by: run_eim
17 Replies
Login or Register to Ask a Question