Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.unix.questions Subject: Re: sorting and reversing lines of a file Keywords: reverse file Message-ID: <962@philmds.UUCP> Date: 26 Feb 89 12:00:12 GMT References: <9056@burdvax.PRC.Unisys.COM> <9510@smoke.BRL.MIL> <899@auspex.UUCP> <2585@pegasus.ATT.COM> <1774@dlvax2.datlog.co.uk> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 45 In article <1774@dlvax2.datlog.co.uk> scm@datlog.co.uk ( Steve Mawer ) writes: [] |Note also that formats such as | | cat file1 file2 > file2 | |will cause your disk to become *very* full (as well as losing the original |contents of file2). Not necessarily so: Script started on Sun Feb 26 12:38:24 1989 philmds> cat /etc/motd Ultrix V2.0-1 System #2: Mon Oct 26 15:31:26 MET 1987 philmds> ls -l file[12] -rw-r----- 1 leo 177 Feb 26 12:37 file1 -rw-r----- 1 leo 273 Feb 26 12:37 file2 philmds> cat file1 file2 >file2 cat: input file2 is output philmds> script done on Sun Feb 26 12:39:11 1989 All you need is a smart cat ( :-); this one will probably do an fstat(2) (on 1), which not all Unixes (Unices ?) support. Leo. P.S. In situations like this one could consider using the 'overwrite' program, as presented in Brian W.Kernighan / Rob Pike's 'The Unix programming environment': $ overwrite file2 cat file1 file2 This situation also arises in cases like: $ sed -f sedfile datafile >/tmp/sed$$; cp /tmp/sed$$ datafile; rm /tmp/sed$$ which can be written like $ overwrite datafile sed -f sedfile datafile 'Overwrite' also takes care of various exception conditions: a sed command that failed, an interrupt etc. which would otherwise mess up the output and/or leave temporary files.