return fp;
fprintf (stderr, "%s: can't open file %s mode %s\n",
progname, file, mode);
exit(1);
}
3.8.18
error.c
error(s1, s2) /* print error message and die */
char *s1, *s2;
{
extern int errno, sys_nerr;
extern char *sys_errlist[], *progname;
if (progname)
fprintf(stderr, "%s: ", progname);
fprintf(stderr, s1, s2);
if (errno > 0 && errno < sys_nerr)
fprintf (stderr, " (%s)", sys_errlist[errno]);
fprintf(stderr, "\n");
exit(1);
}
3.8.19
field1
awk '{ print $'$1' }'
3.8.20
field2
awk "{ print \$$1 }"
3.8.21
fold
# fold: fold long lines
sed 's/\(->/ /g' $* | # convert tabs to spaces
awk '
BEGIN {
N = 80 # folds at column 80
for (i = 1; i <= N; i++) # make a string of blanks
blanks = blanks " "
}
{ if ((n = length($0)) <= N)
print
else {
for (i = 1; n > N; n -= N) {
printf "%s\\\n", substr($0, i ,N)
i += N;
}
printf "%s%s\n", substr(blanks, 1, N-n), substr($0, i)
}
} '
3.8.22
frequent
cat $* |
tr -sc A-Za-z '\012' |
sort |
uniq -с |
sort -n |
tail |
5
3.8.23
frequent2
sed 's/[ \(->][ \(->]*/\
/g' $* | sort | uniq -с | sort -nr | sed 10q
3.8.24
get
# get: extract file from history
PATH=/bin:/usr/bin
VERSION=0
while test "$1" != ""
do
case "$1" in
-i) INPUT=$2; shift ;;
-o) OUTPUT=$2; shift ;;
-[0-9]) VERSION=$1 ;;
-*) echo "get: Unknown argument $i" 1>&2; exit 1 ;;
*) case "$OUTPUT" in
"") OUTPUT=$1 ;;
*) INPUT=$1.H ;;
esac
esac
shift
done
OUTPUT=${OUTPUT?"Usage: get [-o outfile] [-i file.H] file"}
INPUT=${INPUT-$OUTPUT.H}
test -r $INPUT || { echo "get: no file $INPUT" 1>&2; exit 1; }
trap 'rm -f /tmp/get.[ab]$$; exit 1' 1 2 15
# split into current version and editing commands
sed <$INPUT -n '1,/^@@@/w /tmp/get.a'$$'
/^@@@/,$w /tmp/get.b'$$
# perform the edits
awk </tmp/get.b$$ '
/^@@@/ { count++ }
!/^@@@/ && count > 0 && count <= - '$VERSION'
END { print "$d"; print "w", "'$OUTPUT'" }
' | ed - /tmp/get.a$$
rm -f /tmp/get.[ab]$$
3.8.25
get.с
get(fd, pos, buf, n) /* read n bytes from position pos */
int fd, n;
long pos;
char *buf;
{
if (lseek(fd, pos, 0) == -1) /* get to pos */
return -1;
return read(fd, buf, n);
}
3.8.26
getname
who am i | sed 's/ .*//'
3.8.27
idiff.c
/* idiff: interactive diff */