sorting and reversing lines of a file

Leo de Wit leo at philmds.UUCP
Sun Feb 26 22:00:12 AEST 1989


In article <1774 at dlvax2.datlog.co.uk> scm at 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.



More information about the Comp.unix.questions mailing list