help on page break


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help on page break
# 1  
Old 05-21-2009
help on page break

Hi,

i have a file say samp.s which has

123 a b c d
123 e f g h
123 i j k l
123 m n o p
234 a b c d
234 e f g h
234 i j k l

the first 3 characters in each line are considered the key values

i have one more file temp.txt which has

123
234

i want to have a page break in the following manner

123 a b c d
123 e f g h
123 i j k l
(page break)
123 m n o p
(page break)
234 a b c d
234 e f g h
234 i j k l
(page break)

After 3 lines i need to have a page break.

can someone help me on this.

Thanks,
Sheema
# 2  
Old 05-21-2009
if you have Python
Code:
#!/usr/bin/env python
temp=open("temp.txt").read().split("\n")
d={}
for line in open("file"):
    old=line
    line=old.split()
    if line[0] in temp:        
        d.setdefault(line[0],[])
        d[line[0]].append(old)        
for k in temp:
    if len(d[k]) %3 !=0:
        d[k].append("\n")
    for n,item in enumerate(d[k]):         
        if n%4==0:    
            d[k][n-1]=d[k][n-1].strip()        
            d[k].insert(n,"\n\n")
    d[k].pop(0)        
    print ''.join(d[k])

output
Code:
# more temp.txt
123 a b c d
123 e f g h
123 i j k l
123 m n o p
123 q r s t
123 u v w x
123 o o o o
234 a b c d
234 e f g h
234 i j k l
234 a b c d
234 e f g h
234 i j k l
234 w x y z

# ./test.py
123 a b c d
123 e f g h
123 i j k l

123 m n o p
123 q r s t
123 u v w x

123 o o o o

234 a b c d
234 e f g h
234 i j k l

234 a b c d
234 e f g h
234 i j k l

234 w x y z


Last edited by ghostdog74; 05-21-2009 at 10:08 AM..
# 3  
Old 05-21-2009
ghostdog74,

I hope it's not the Output Sheema is expecting.
# 4  
Old 05-21-2009
Quote:
Originally Posted by panyam
ghostdog74,

I hope it's not the Output Sheema is expecting.
??? don't understand.
anyway, i assume the criteria to add newline is when the first column corresponds to what
temp.txt has.
# 5  
Old 05-21-2009
According to Sheema's output , there should be a pagebreak after every three lines ( of course which should present in temp.txt) and if the first field is varied in the list of next three lines then page break should be done .

123 a b c d
123 e f g h
123 i j k l
(page break)
123 m n o p
(page break)
234 a b c d
234 e f g h
234 i j k l
(page break)
# 6  
Old 05-22-2009
@ghostdog74 - Thanks for the input
@Panyam - That's exactly the requirement.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Print multiple copies page by page using lp command

Hi I have a pdf file that is being generated using the rwrun command in the shell script. I then have the lp command in the shell script to print the same pdf file. Suppose there are 4 pages in the pdf file , I need to print 2 copies of the first page, 2 copies of the second page , then 2... (7 Replies)
Discussion started by: megha2525
7 Replies

3. Web Development

Page load time- local page

Hi Is there a way to calculate the page load time, I am trying to calculate the load time of a page locally. I found tools to do this over http or https but none that work locally. Any ideas? Thanks. (4 Replies)
Discussion started by: jamie_123
4 Replies

4. Shell Programming and Scripting

Page Break in a file for printing

Hi, We have 1lac records in source file and unix script will genarate around 1000 files. From target location the files are taking for printing on physical papers. the page size limitation : 256 Lines Can you please tell me how to insert the page break in a flat file for printer. (5 Replies)
Discussion started by: koti_rama
5 Replies

5. UNIX for Dummies Questions & Answers

Insert a break page after certain string using SED

Hi: I have 2 files: teststring.txt and a tempfile.txt teststring file contains: s/Primary Ins./\n1/g I'm trying to search for "Primary Ins." string in tempfile. For every "Primary Ins." string that is found, a new line is inserted and put in number 1. Then, write out the newfile... (7 Replies)
Discussion started by: newbeee
7 Replies

6. Shell Programming and Scripting

Page Break in large file

Hi, The shell script inserting the millions of rows into target flat file system and handling the line number for each line. We need a page break line after every 10,000 lines. is there any command to insert a page break line into target file. (3 Replies)
Discussion started by: koti_rama
3 Replies

7. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

8. UNIX for Dummies Questions & Answers

display command output page per page

Good afternoon, I wonder how i could use unix commands to ease the reading of long command result output ? like the "php -i" or any other command that returns a long answer. I could not find the right terms to Google it or search the forum. Therefore I bother you with this question. ... (3 Replies)
Discussion started by: Mat_k
3 Replies

9. Solaris

High Page In and Executable page In

Hi, Currently I'm experience very high page ins on my system running on solaris 10. From vmstat, the page ins figure is very high, further drill down shows the page ins are from file system and occassional spike in executable page ins. Details as follow: oracle@perch:/files>> vmstat 5... (9 Replies)
Discussion started by: srage
9 Replies

10. Shell Programming and Scripting

Page Break with AWK or SED

Hello All, I am new to unix scripting, I have an urgent issue Is it possible to do a group by on the last column and then a page break on the text file. For example I have a text file, below is the example data STRT 2154081~VA ~23606 ~TM14~8506~1485 STRT 2130893~VA ~23602 ~TM15~8602~1586... (4 Replies)
Discussion started by: udaybo
4 Replies
Login or Register to Ask a Question