Thread View: comp.unix.shell
4 messages
4 total messages
Started by Fabrice Le Metayer
Sat, 08 Sep 1990 05:46
Re: How to do <cmd> file | hold file
Author: Fabrice Le Metayer
Date: Sat, 08 Sep 1990 05:46
Date: Sat, 08 Sep 1990 05:46
20 lines
1202 bytes
1202 bytes
In article <1727@pbhyd.PacBell.COM> rjw@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.\$\$ \!\$
--
Fabrice
--
Fabrice Le Metayer DOMAIN : fabrice@sj.ate.slb.com
Schlumberger Technologies - ATE UUCP : {amdahl,decwrl,uunet}!sjsca4!fabrice
San Jose, CA 95110 BELL : (408) 437-5114
Re: How to do <cmd> file | hold file
Author: Dan Bernstein
Date: Sun, 09 Sep 1990 03:14
Date: Sun, 09 Sep 1990 03:14
16 lines
1094 bytes
1094 bytes
In article <1990Sep8.054623.3822@sj.ate.slb.com> fabrice@sj.ate.slb.com writes: > 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.\$\$ \!\$ Much better is % alias transform '(rm \!:1;\!:2* > \!:1) < \!:1' which is used as, e.g., % transform foo.c grep -v '^/\*###' to strip comments inserted by error(1). It doesn't demand a temporary file. It can release the disk space of the original as soon as the command closes it. And it doesn't pass foo.c as an argument if the command is just a filter. ---Dan
Re: How to do <cmd> file | hold file
Author: Gordon C. Galligher
Date: Sun, 09 Sep 1990 17:38
Date: Sun, 09 Sep 1990 17:38
35 lines
2255 bytes
2255 bytes
In article <1990Sep8.054623.3822@sj.ate.slb.com> fabrice@sj.ate.slb.com writes:
>In article <1727@pbhyd.PacBell.COM> rjw@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@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_
Re: How to do <cmd> file | hold file
Author: Barton E. Schaefer
Date: Sun, 09 Sep 1990 17:53
Date: Sun, 09 Sep 1990 17:53
31 lines
1685 bytes
1685 bytes
In article <8147:Sep903:14:3990@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
} In article <1990Sep8.054623.3822@sj.ate.slb.com> fabrice@sj.ate.slb.com writes:
} > alias apply \!\* \> /tmp/apply.\$\$ \; cp /tmp/apply.\$\$ \!\$
}
} Much better is
}
} % alias transform '(rm \!:1;\!:2* > \!:1) < \!:1'
Of course, if you WANT to put the file name at the end rather than at
the beginning, you can use (sticking with the original alias name):
% alias apply '( rm \!:$ ; \!:1- > \!:$ ) < \!:$'
but I agree that listing the file first is clearer.
The one problem I see with this is that there ought to be a way to abort
if the rm doesn't happen. E.g.,
% transform foo.c grep -v '^/\*###'
rm: override protection 444 for foo.c?
Unfortunately, no matter what answer is given to this question, "rm"
exits with status 0. In this particular case the grep command will
fail (on an "n" response) due to lack of write permission on foo.c,
but there are other cases where a problem might occur if the file isn't
rm'd.
Using "mv" would solve this problem, but requires a decision of where
to move the file.
--
Bart Schaefer schaefer@cse.ogi.edu
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads