How to do <cmd> file | hold file

Gordon C. Galligher gorpong at ping.uucp
Mon Sep 10 03:38:53 AEST 1990


In article <1990Sep8.054623.3822 at sj.ate.slb.com> fabrice at sj.ate.slb.com writes:
>In article <1727 at pbhyd.PacBell.COM> rjw at PacBell.COM (Rod Williams) writes:
>>>                          ...suppose I want to sort a file
>>>and place the result in the same file without destroying it,
>>
>>Doesn't 'sort' allow you to do this already in one easy step?
>>
>>	sort -o<file> <samefile>
>>
>>...or did I misunderstand the question?
>
>I use the following C-shell alias to get the output of a command into
>the file it applies to. The command should be of the form "<cmd line> <file>".
>
>	alias apply  \!\* \> /tmp/apply.\$\$ \; cp /tmp/apply.\$\$ \!\$

You will probably wish to add the following to your alias: \; rm /tmp/apply.\$\$
Without it, you may end up with quite a lot of files in the /tmp directory,
and depending upon the output of the command, this can begin to add up.

Before anyone writes:  "Just use 'mv'"  there is a very valid reason for using
'cp' as opposed to 'mv':  'cp' preserves the permissions on the file you are
copying to, whereas 'mv' does not (ie:  Mv makes the destination file the
same permissions as the source file, cp preserves the permissions on the
destination file).  If you do not believe me, then experiment on your own by 
setting umask, creating a couple of files and making the permissions different
and then using 'mv' and 'cp' combinations and see what happens.

		-- Gordon.
-- 
Gordon C. Galligher	9127 Potter Rd. #2E	Des. Plaines, Ill.    60016-4881
     telxon!ping%gorpong at uunet.uu.net (not tested)  (Is this even legal??)
     ...!uunet!telxon!ping!gorpong      (tested)    (And it works!)
"It seems to me, Golan, that the advance of civilization is nothing but an
 exercise in the limiting of privacy." - Janov Pelorat -- _Foundation's Edge_



More information about the Comp.unix.shell mailing list