🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
5 messages
5 total messages Started by Jeffrey Lawrence Haferman Fri, 07 Sep 1990 17:57
How to do <cmd> file | hold file
#1088
Author: Jeffrey Lawrence Haferman
Date: Fri, 07 Sep 1990 17:57
20 lines
945 bytes
I had a shell script that used to perform what I have in the
subject line.  For example,  suppose I want to sort a file
and place the result in the same file without destroying it,
e.g.

   % sort file > tmp
   % mv tmp file

I would like a command 'hold' which would do the above via

   % sort file | hold file

Got a good one liner for this (in c-shell)?


Jeff Haferman                            internet: jlhaferman@icaen.uiowa.edu
Department of Mechanical Engineering
University of Iowa
Iowa City IA  52240
Re: How to do <cmd> file | hold file
#1096
Author: Rod Williams
Date: Fri, 07 Sep 1990 22:47
13 lines
969 bytes
>                          ...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?
-- 
* * * * * * * * * * * * * * * * * * * * *         * * * * * * * * * *
*   Rod Williams                        *         entertain         *
*   Pacific Bell - San Ramon CA         *         a thought         *
* * * * * * * * * * * * * * * *         * * * * * * * * * * * * * * *
Re: How to do <cmd> file | hold file
#1102
Author: Joe Smith
Date: Sat, 08 Sep 1990 00:34
16 lines
1267 bytes
In article <2274@ns-mx.uiowa.edu> jlhaferman@l_cae07.icaen.uiowa.edu (Jeffrey Lawrence Haferman) writes:
>For example, suppose I want to sort a file and place the result in the same
>file without destroying it, e.g.
>   % sort file > tmp; mv tmp file

You can use "sort file -o file" for that particular problem.  (It's in the
man pages.)

In general, you have to find a suitable location to hold the file, then
mv it to the destination.  Buffering the entire file in RAM does not work
for large files.
-- 
Joe Smith (408)922-6220 | SMTP: jms@tardis.tymnet.com or jms@gemini.tymnet.com
BT Tymnet Tech Services | UUCP: ...!{ames,pyramid}!oliveb!tymix!tardis!jms
PO Box 49019, MS-C41    | BIX: smithjoe | 12 PDP-10s still running! "POPJ P,"
San Jose, CA 95161-9019 | humorous dislaimer: "My Amiga speaks for me."
Re: How to do <cmd> file | hold file
#1106
Author: Dan Bernstein
Date: Sun, 09 Sep 1990 03:04
22 lines
1449 bytes
In article <1215@tardis.Tymnet.COM> jms@tardis.Tymnet.COM (Joe Smith) writes:
> In article <2274@ns-mx.uiowa.edu> jlhaferman@l_cae07.icaen.uiowa.edu (Jeffrey Lawrence Haferman) writes:
    [ how to sort a file and place output back into same file? ]
  [ sort -o file file works ]
> In general, you have to find a suitable location to hold the file, then
> mv it to the destination.

No, you don't.

  % ( rm file; foo > file ) < file

foo's input will point at the old file; its output will go into the new
file. If foo reads all its input early and close()s to indicate this,
the disk space for the original will immediately disappear, provided
that it had only one link. If it had several links then the others will
stay around, entirely unaffected.

(I think cp foo bar should work like ( rm -f bar; cat > bar ) < foo, so
that other links to bar won't be affected; but POSIX 1003.2 apparently
disagrees and has cp foo bar work like cat < foo > bar. Oh, well.)

---Dan
Re: How to do <cmd> file | hold file
#1108
Author: Neil Rickert
Date: Sun, 09 Sep 1990 14:00
15 lines
1346 bytes
In article <8029:Sep903:04:5390@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:
>(I think cp foo bar should work like ( rm -f bar; cat > bar ) < foo, so
>that other links to bar won't be affected; but POSIX 1003.2 apparently
>disagrees and has cp foo bar work like cat < foo > bar. Oh, well.)
>
 Please don't ever implement 'cp' in the way you suggest.  Doing so would
change file ownership, group, and permissions, not to mention that it would
fail if the file is in directory for which you do not have write permission.
It also messes up multiple links and symbolic links to the file.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115.                                  +1-815-753-6940
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