Splitting of files - Addition of Page Number in the Trailer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Splitting of files - Addition of Page Number in the Trailer
# 1  
Old 08-27-2012
Question Splitting of files - Addition of Page Number in the Trailer

Hi,

I need your help on the following Scenario :

Consider a file has 650 records and I need to split this file into 4 files having a maximum of 200 records in each of them and also for the first splitted file it should get appended with Page 1 as a trailer( Similarly for the second file, Page 2 should be the Trailer..For Third it should be Page 3 and so on..).

How can we do this ?? Smilie
# 2  
Old 08-27-2012
Hi


Code:
$ cat file
1
2
3
4
5
6
7
8
9
10


Code:
$ awk '{print > "FILE"x;}!(NR%4){print "PAGE "x > "FILE"x;x++;}END{print "PAGE "x > "FILE"x}' x=1 file

Code:
$ cat FILE1
1
2
3
4
PAGE 1
$ cat FILE2
5
6
7
8
PAGE 2
$ cat FILE3
9
10
PAGE 3


Replace 4 with 200 in your case.

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 08-27-2012
Hi Guru,

Can u explain this code a bit ? Smilie
# 4  
Old 08-27-2012
Hi

Code:
{print > "FILE"x;}

-> Write every record to the file "FILE"x where x is 1,2,3 and so on. x starts with 1 and gets incremented for every 4 records.

Code:
!(NR%4){print "PAGE "x > "FILE"x;x++;}

-> When a line which is a multiple of 4(4,8,12..) is reached, write the trailer record and increment x.

Code:
END{print "PAGE "x > "FILE"x}

-> For the last file, write the trailer record.

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 5  
Old 08-27-2012
Hi,

Got The Logic..Thanks a lot !! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Page number with total number of pages, EG Page 1 of 5

So I've worked how to add page numbers based on regex. It's using the footer text. How do we get the total amount added so we have page number with the total number of pages? Desired output: Page No:1 of 5 Thanks in advance. (15 Replies)
Discussion started by: tugar
15 Replies

2. Shell Programming and Scripting

Splitting number (no delimiter)

Hi ! here is my data file column 1 fields 2597 121297 13599 130498 want to print like this 02/05/1997 12/12/1997 13/05/1999 13/04/1998 how to split each field and print in correct way if there was delimiter I would have done some thing like this awk '{split($0,a,":");... (13 Replies)
Discussion started by: Akshay Hegde
13 Replies

3. Shell Programming and Scripting

Replace column by random number addition

Here is my problem:- I have a file with pipe separated values. CR|20121021|079|ABC|N|DLS|00038|DLS|04750|1330597704|634234|634|0 CR|20121021|079|ABC|N|DLS|00038|DLS|05118|2071690102|354|351|3 CR|20121021|079|ABC|N|DLS|00038|DLS|05140|960051505|1088|1088|0... (4 Replies)
Discussion started by: Yoda
4 Replies

4. Shell Programming and Scripting

script for adding page number before page breaks

Hi, If there is an expert that can help: I have many txt files that are produced from pdftotext that include page breaks the page breaks seem to be unix style hex 0C. I want to add page numbers before each page break as in : Page XXXX Regards antman (9 Replies)
Discussion started by: antman
9 Replies

5. Shell Programming and Scripting

How to Addition and subtraction..using files

Hi all, Thanks in advance I want to do simple calculations..using files for example: i have 2 files called anish.txt and kumar.txt anish.txt contains value 10 and kumar.txt contains value 5 anish.txt - kumar.txt = 5 i want to display like this how to do this process... (17 Replies)
Discussion started by: anishkumarv
17 Replies

6. UNIX for Dummies Questions & Answers

Multiple number addition

Friends , Can u tel me how can i have done multiple addition using shell script ? Expected Output can be : 1 4 6 --------- Total - 11 (4 Replies)
Discussion started by: meetsubhas
4 Replies

7. Shell Programming and Scripting

incremental addition of hex decimal number in one field

Hi I want to incremental add hex decimal number to a particula field in file eg: addr =123 dept1=0 addr = 345 dept2 =1 addr2 = 124 dept3 =2 . . . . . . addr3 =567 dept15 =f Is there any command which add... (8 Replies)
Discussion started by: diddi_linux
8 Replies

8. Shell Programming and Scripting

Merge text files while combining the multiple header/trailer records into one each.

Situation: Our system currently executes a job (COBOL Program) that generates an interface file to be sent to one of our vendors. Because this system processes information for over 100,000 employees/retirees (and growing), we'd like to multi-thread the job into processing-groups in order to... (4 Replies)
Discussion started by: oordonez
4 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
Login or Register to Ask a Question