ref: 9d8657023ecb154ca8ad3ab53fde5ac54440e42e
parent: f5fe39ad7afa9b761821178ba57f28cea03396b8
parent: da81fd83cef21d07ef613535867e97ab77ed09a8
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Sun Oct 23 20:54:01 EDT 2011
merge
--- /dev/null
+++ b/rc/bin/ssam
@@ -1,0 +1,41 @@
+#!/bin/rc
+# ssam - stream interface to sam
+
+flagfmt='n,e script,f sfile'
+args='[ file ... ]'
+if(! ifs=() eval `{aux/getflags $*}){
+ usage
+ exit usage
+}
+
+if(~ $#flage 0 && ~ $#flagf 0) {
+ if(~ $#* 0) {
+ usage
+ exit usage
+ }
+ flage=$1
+ shift
+}
+
+if(~ $#TMPDIR 0)
+ TMPDIR=/tmp
+tmp=$TMPDIR/ssam.tmp.$user.$pid
+cat $* >$tmp
+
+{
+ # select entire file
+ echo ',{'
+ echo k
+ echo '}'
+ echo 0k
+
+ # run scripts, print
+ if(! ~ $#flagf 0)
+ cat $flagf
+ if(! ~ $#flage 0)
+ echo $flage
+ if(~ $#flagn 0)
+ echo ,
+} | sam -d $tmp >[2]/dev/null
+
+rm -f $tmp
--- /dev/null
+++ b/sys/man/1/ssam
@@ -1,0 +1,72 @@
+.TH SSAM 1
+.SH NAME
+ssam \- stream interface to sam
+.SH SYNOPSIS
+.B ssam
+[
+.B -n
+]
+[
+.B -e
+.I script
+]
+[
+.B -f
+.I sfile
+]
+[
+.I file ...
+]
+.SH DESCRIPTION
+.I Ssam
+copies the named
+.I files
+(standard input default) to the standard output, edited by a script of
+.IR sam
+commands (q.v.).
+When the script starts, the entire input is selected.
+The
+.B -f
+option causes the script to be taken from file
+.IR sfile .
+If there is a
+.B -e
+option and no
+.BR -f ,
+the flag
+.B -e
+may be omitted.
+The
+.B -n
+option suppresses the default output.
+.ne 4
+.SH EXAMPLES
+.TP
+.B ssam -n ,10p file
+Print first 10 lines of file.
+.TP
+.B ssam 'y/[a-zA-Z]+/ c/\en/' *.ms
+Print one word per line.
+.TP
+.B ssam 's/\en\en+/\en/g'
+Delete empty lines from standard input.
+.TP
+.B ssam 's/UNIX/& system/g'
+Replace every instance of
+.L UNIX
+by
+.LR "UNIX system" .
+.TP
+.B ssam 'y/[a-zA-Z]+/ c/\en/' | grep . | sort | uniq -c
+Count frequency of words read from standard input.
+.SH SOURCE
+.B \*9/bin/ssam
+.SH SEE ALSO
+.IR sed (1),
+.IR sam (1),
+.IR regexp (7)
+.PP
+Rob Pike,
+``The text editor sam''.
+.SH BUGS
+Ssam consumes all of standard input before running the script.