Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saparate a file into "pages" 2

Status
Not open for further replies.

mremoos

Programmer
Jan 16, 2004
6
PL
Here's the problem: I need to separate a file into "pages" of 10 lines each. The page must contain 8 lines of the input file, the last two must be like this:
========================
x/xx (current page/total number of pages)

so a "page" should look like this:
dsfg
sdfg
sdfg
dfg
dfg
dfg
dfg
df
=====================
1/xx
So far I failed. Any help much apreciated.
 
Try something like this:
Code:
awk 'BEGIN{p=1}
{t[NR]=$0;++l;if(l>1 &&(l%8)==1)++p}
END{i=1
 fmt="========================\n%d/%d\n"
 for(j=1;j<=p;++j){
  for(k=1;k<=8;++k){
   print (i<=l ? t[i] : &quot;&quot;)
   ++i
  }; printf fmt,j,p
}}' /path/to/inputfile

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top