[comp.misc] Your favourite UNIX pipe ?

andy@coma.UUCP (Andreas Lampen) (05/09/90)

Please send me your most favourite (sophisticated, cryptic, funny) pipe !

I want to open the list with a quite common one:
  soelim foo.ms | refer -sAD -l4,2 | pic | troff -Talw -ms | tps | lpr -Plw

and a cross machine pipe:
  tar cf - | dd bs=20k | rsh coma "cd blubber; dd bs=20k | tar xf -"

We are currently working on a concept for an object oriented shell for
UNIX and (of course) ran into difficulties when trying to model the
pipe mechanism. We came up with a first idea but soon found an example
where this didn't work ... .

Now, this inquiry shall set up a list of pipes that helps us to validate
our ideas. Additionally, I think such a list will be quite interesting
for UNIX users. I will post a summary anyway.

Thanks in advance,
		   Andy
-- 
----
  Andreas Lampen, Tech. Univ. Berlin
      andy@coma.cs.tu-berlin.de

merlyn@iwarp.intel.com (Randal Schwartz) (05/10/90)

In article <690@coma.UUCP>, andy@coma (Andreas Lampen) writes:
|   tar cf - | dd bs=20k | rsh coma "cd blubber; dd bs=20k | tar xf -"

I would use:
	tar cf - . | dd obs=20k | rsh coma "cd blubber && tar xf -"

The second dd contributes nothing.

The "&&" prevents you from extracting a whole mess of stuff in the
wrong directory should you "fat-finger" the target directory.

(Leaving the '.' off the tar sends an empty archive... you gotta send
at least *something*. :-)

I also usually leave off the first dd, because tar writes its stuff
20*512 bytes at a time anyway.

If I'm nosy, it comes out as:

	tar cf - . | rsh coma "cd blubber && tar xvf -"

so I can get a progress report.  Run it in a separate window (GNU
Emacs or bitmap window, take yer pick).

Just another tar baby,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

bush@evax.arl.utexas.edu (Joe Bush) (05/26/90)

	Here is one I concocted to search for key words in include
files:

echo -n "key=";set kw=`line`;find /usr/include/. /sys/. -name \*.h -print | xargs hgrep "$kw" {} 

	I keep a file of such one-liners like the one above (file of
one line pipe-programs is named $HOME/.syscom) and have the following
line in my .cshrc:

alias g 'set j=`cat ${home}/.syscom|wc -l`;source -h ${home}/.syscom; history | tail -"$j"'

	Then when I enter "g" from the keyboard, my csh history
mechanism gets primed for easy execution. I find it quite handy...

	- Joe
-- 
	  bush@evax.arl.utexas.edu		  Vax Systems Manager
	  (817) 273 - 3333			  CSE Dept. UT-Arlington
	  Office Rm 221 EB2			  403 South Cooper
	  P.O. Box 19015			  Arlington, Texas 76019

trt@rti.rti.org (Thomas Truscott) (05/30/90)

Here is a shell script that has a pipeline in it somewhere.
	Tom Truscott

#! /bin/sh

# you pick a word, e.g. "hangman".
# if antihang guesses "a", the new pattern is ".a...a.".
# if antihang then gueses "t", the new pattern is ".a...a." (no change).
# antihang fails on words not in /usr/dict/words

wordlist=/usr/dict/words
myguess=e	guesses=
while [ "$myguess" ]; do
	guesses=$guesses$myguess
	echo -n "I guess $myguess, new pattern: "
	read pattern
	srchpat=`echo "$pattern" | sed "s/\./[^$guesses]/g"` 
	myguess=`grep "^$srchpat$" $wordlist | \
		sed -e "s/[$guesses]//g" -e 's/\(.\)\(.*\)\1/\1\2/g' -e 's/./&\\
/g' | \
		sort |  uniq -c |  sort -nr | \
		sed -n -e 's/^.*\([^ ]\)$/\1/p' | sed 1q`
done

maart@cs.vu.nl (Maarten Litmaath) (05/30/90)

In article <3870@rtifs1.UUCP>,
	trt@rti.rti.org (Thomas Truscott) writes:
)...
)	myguess=`grep "^$srchpat$" $wordlist | \
)		sed -e "s/[$guesses]//g" -e 's/\(.\)\(.*\)\1/\1\2/g' [...]
                                            ^^^^^^^^^^^^^^^^^^^^^^^^
                                            Why?

Anyway, a nice script, Tom!
What do you think of the following modified version?

--------------------cut here--------------------
#!/bin/sh
# you pick a word, e.g. "hangman".
# if antihang guesses "a", the new pattern is ".a...a.".
# if antihang then gueses "t", the new pattern is ".a...a." (no change).
# antihang fails on words not in /usr/dict/words
# Original: Tom Truscott
# Modifications: Maarten Litmaath
 
wordlist=/usr/dict/words
myguess=e       guesses=
NL='
'

while :
do
	guesses=$guesses$myguess
	echo -n "I guess $myguess, new pattern: "
	read pattern
	case $pattern in
	*.*)
		srchpat=`echo "$pattern" | sed "s/\./[^$guesses]/g"` 
		myguess=`
			sed -e "/^$srchpat$/!d" -e "s/[$guesses]//g" \
				-e 's/./&\\'"$NL/g" -e 's/.$//' $wordlist |
			sort |  uniq -c |  sort -nr |
			sed -e 's/.*\(.\)$/\1/' -e q
		`
		;;
	*)
		break
	esac
done
--
 "COBOL is the revenge of some witch burned |Maarten Litmaath @ VU Amsterdam:
   in Salem, [...]"  (Bill Davidsen)  |maart@cs.vu.nl, uunet!cs.vu.nl!maart