Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!haven!adm!xadmx!rbj@nav.icst.nbs.gov From: rbj@nav.icst.nbs.gov (Root Boy Jim) Newsgroups: comp.unix.questions Subject: sorting and reversing lines of a file Message-ID: <18706@adm.BRL.MIL> Date: 14 Mar 89 17:03:40 GMT Sender: news@adm.BRL.MIL Lines: 23 ? From: Francois-Michel Lang ? I need utilities to do two things: ? (1) reverse the order of lines in a file ? but leave the lines themselves intact. ? The Unix utility does just the opposite of this. You don't want to do this, but it does work! sed -e '1{;h;d;}' -e '$!{;G;h;d;}' -e '$G' Well, up to a point anyway. An `ls -l /etc | wc -l' produces 140 lines on our system. Piping the ls to the sed command produced only about 70 lines, giving a total of 4000 characters. That seems to be the limit. Don't forget to quote the `!' if using csh. The semicolons are an undocumented feature. An awk script would be a better way to do this. Tail -r seems to be the best buggestion unless you are reversing really BIG files. In that case you probably do want to write a C program. There's just no escaping the buffering problem. Catman Rshd Author of "The Daemonic Versions"