ken@boring.UUCP (06/04/85)
A quick hack I wrote a few years back. For example, I sort my .newsrc file thus: alias sortn '( fgrep : ~/.newsrc | sort ; fgrep -v : ~/.newsrc | sort ) | hold ~/.newsrc' Runs on 4.2. Some mods may be needed for other systems. #!/bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #!/bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # hold.1 # hold.c # This archive created: Mon Jun 3 15:22:51 1985 # By: Ken Yap () export PATH; PATH=/bin:$PATH if test -f 'hold.1' then echo shar: over-writing existing file "'hold.1'" fi cat << \SHAR_EOF > 'hold.1' .TH HOLD 1 "26/4/85" .SH NAME hold \- collect standard input into a file .SH SYNOPSIS .B "hold file" .SH DESCRIPTION .I Hold collects standard input and writes it to the file. The difference between it and .I > or tee is that the file does not exist by that name until EOF is seen. This is useful for putting the results of pipelines back into the original file. If .I hold is interrupted the temporary file is deleted. .SH EXAMPLES tr 'A-Z' 'a-z' < prog | hold prog .SH AUTHOR Ken Yap ( University of Sydney ) .SH FILES holdXXXXXX temporary .SH SEE ALSO tee(1) SHAR_EOF if test -f 'hold.c' then echo shar: over-writing existing file "'hold.c'" fi cat << \SHAR_EOF > 'hold.c' /* ** hold - program to copy standard input into a file ** and rename it to the first argument after end of file ** useful for putting output of programs like tr back ** into the original file ** Ken Yap, Sydney University, March 1982. */ #include <stdio.h> #include <signal.h> char tmpname[64]; char buffer[BUFSIZ]; main(argc,argv) int argc; char **argv;{ if(argc < 2){ fprintf(stderr,"Usage: %s file\n",argv[0]); exit(1); } hold(argv[1]); exit(0); } hold(name) char *name;{ register char *p; register int length,fd; int (*oldsig)(); char *mktemp(),*rindex(); int read(),write(),link(); extern catch(); (int (*)()) signal(); if((p = rindex(name,'/')) == NULL) length = 0; else length = p - name + 1; strncpy(tmpname,name,length); strcpy(tmpname + length,mktemp("holdXXXXXX")); #ifdef DEBUG fprintf(stderr,"tmpname is %s\n",tmpname); #endif if((oldsig = signal(SIGINT,SIG_IGN)) == SIG_DFL) signal(SIGINT,catch); #ifdef DEBUG fprintf(stderr,"oldsig is %d\n",oldsig); #endif if((fd = creat(tmpname,0644)) < 0){ perror(name); exit(2); } while((length = read(0,buffer,BUFSIZ)) > 0) write(fd,buffer,length); close(fd); signal(SIGINT,SIG_IGN); unlink(name); if(link(tmpname,name) < 0){ perror(name); exit(3); } unlink(tmpname); } catch(){ unlink(tmpname); exit(0); } SHAR_EOF # End of shell archive exit 0 -- UUCP: ..!{seismo,okstate,garfield,decvax,philabs}!mcvax!ken Voice: Ken! Mail: Centrum voor Wiskunde en Informatica, Kruislaan 413, 1098 SJ, Amsterdam.