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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to sort and put a page break on a text file

Status
Not open for further replies.

udaybo

Programmer
Jun 2, 2008
23
US
Hello,

I have a text file like below example, I would like to do a sort by the last field and put a page break after each group

How can I do this using sed or awk

VA 23602 TM15 8802 1588
VA 23606 TM14 8506 1486
VA 23662 TM17 8362 1783
VA 23662 TM17 8362 1588
VA 23188 TM60 9188 6091
VA 23185 TM41 9085 1486

Thank you
 

Try:
Code:
sort -k5,5 my_data|awk '{if (x != $5) printf "\f"; x=$5; print $0;}'
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you,

I got the sort working, but the page break isn't.

Thanks again for your help
 
LKBrwnDBA's code looks fine... what exactly do you mean by a 'page break' here? If you just want a gap, try replacing printf "\f" with printf "\n\n".

Annihilannic.
 
Thanks for you reply Annihilannic, by page break I meant, when I print the report each group after the sort should be printed in a different page.

I am very new to AWK, I am not even sure if that could be done or not.

Thanks again
 
print "\f" put the ASCII code for FormFeed (Hex 0C).
So, how do you print the report ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PH

I am gonna run my script through KSH and send the text file to a particular location, so that the users could print out the file.

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top