sorting and reversing lines of a file

Michael Morrell morrell at hpsal2.HP.COM
Wed Mar 1 07:44:23 AEST 1989


/ hpsal2:comp.unix.questions / leo at philmds.UUCP (Leo de Wit) /  4:00 am  Feb 26, 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
----------

Interesting.  I never noticed that "cat" would complain if one of its input
files was the saem as its output.  Unfortunately, although this feature
prevents the disk from filling up, it still causes the original contents of
file2 to be lost, resulting in file2 being a copy of file1 (at least, this is
the behavior on HP-UX).  Since the shell is truncating file2 before cat is
invoked, you need a smarter shell, not a smarter cat, to avoid this problem.

   Michael



More information about the Comp.unix.questions mailing list