# Description # This file contains a various 'pipes' which I have been induced to # write for various reasons. A pipe is essentially a set of Unix commands # which have been joined together using the 'pipe' symbol or device. # All that a pipe does is to take the 'output' of one particular program # and make it the input for another program. This appears a simple idea # but in reality it allows for a creative process to occur where by the # system user can constructively build successively more complex or # more useful or more interesting or more elegant programs using this # device. # # The normal flow of program development is very different from this # process and this flow has very much to do with the sorts of 'modes' and # moods which the human brain is experiencing. Simply put, normal # program development takes place in an extremely analytical fashion: # an API is built, that is, an Application Programming Interface is # developed in a kind of pyramid type of manner. That is to say, that # the most basic and perhaps abstract kinds of functions or objects # are constructed first, and then progressively more conceptually complex # 'units' or function or objects are constructed until finally the # units are sufficiently complex to actually solve the problem which you # or they actually set out to solve. # # For example: You want a piece of software which will answer people's # questions about their 'relationship' problems with their current partner # (it should be noted that this is a particularly difficult problem # to tackle- you would probably be better off writing some kind of # accounting system or invoicing program). # # In order to solve the above problem you first need to write some # fairly basic 'units' or objects or functions. For example, assuming that # the people asking the questions about their relationships are going to # be typing those questions on some computer, you are going to need # some units of code that can deal with mis-spellings, slang words, # strange dialects of what ever language you happen to be dealing with # and so on. If you dont have these code units you are not going to # be able to interpret the questions that people are asking of # your program. # # Congratulations, by identifying these 'sub-needs' or sub-requirements # what you have essentially done is to take the first step in building # and API or an Application Programming Interface. # # Any way the point is, that when you identify all these sub-requirements # such as the requirement for a piece of code that can correct mis-spellings # etc, what you have to do is THINK in a different manner. # # My point is that you set out to solve a particular problem, but the # process of building an API to solve that problem diverts you from the # solving of the problem. This is why the 'pipeline' philosophy is important # ; because you can build the solution to the problem with-out having to # lose site of the significance of the problem which you were trying to # solve in the first place. The pipe-line philosophy allows you to build # a solution incrementally rather that 'pyramidically'. I think this is an # important idea, although there are probably not many people who would # agree with me # # This idea of solving incrementally rather than pyramidically is closely # related to the idea that a good Bash shell or other type of shell is a # prototyping mechanism. No-body, I think, would dispute that in order # to create a program that is fast, efficient and well written you CANNOT # use a Bash shell or something similar. The program needs to end up in # something like Java or C or Assembler. But the process of building the # program is also significant. # # Allow me to refer back to my previous example; you wanted to write a # program which solves peoples relation-ship problems but in order to # to this you have to write code that checks for mis-spellings in the # questions which they are submitting to your program. The point is, that # the sort of thought processes required to write spell checking code are # completely different from the sort of thought processes required to # write relation-ship solving code. This is the problem. The API programming # philosophy forces you to forget the original problem which you set out # to solve and this is not a good thing. # # Other Notes: # The pipe-lines represented here may quite possible not work in a # 'cut and paste' sort of way. In some cases they are simply incomplete # ideas # Mirror a website with wget to a depth of 3 hyperlinks wget -r -l2 http://www.geocities.com/matth3wbishop/ # A pipe-line to take a plain text file, format it as a single list # of unique, alphabetically sorted words, and to translate each of those # words using a unix/ linux / debian program called i2e.sh # The -e switch of i2e specifies that only exact matches should # be used. Otherwise the word 'a' will return hundreds of matches. for w in $(cat tutor-phrase-help.txt | tr '[A-Z]' '[a-z]' | sed 's/[^a-z]/ /g' | tr ' ' '\n' | sed '/^ *$/d' | sort | uniq); do i2e.sh -e $w; done | sed "/^ *$/d" | more # Slightly improved display layout but becoming quite slow for line in $(cat tutor-phrase-help.txt | sed "/^[^a-zA-Z]*$/d" | tr ' ' '#'); do s=$(echo $line | tr '#' ' '); echo $s; for v in $(echo $s | tr '[A-Z]' '[a-z]' | sed "s/[^a-z]/ /g"); do printf '('; i2e.sh -e $v | sed "/^ *$/d" | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | sed 's/A (abrev\. de amperio)/uno/i' | sed "s/^ *//g" | sed "s/ *$//g" | tr '\n' '|'; printf ') '; done; echo ""; echo "+++++++++"; done | sed 's/[|][)]/)/g' | more # A pipe to do something once for each line of a particular file # Alternatively you could use xargs, but I have difficuly getting # xargs to do what I want it to do. for w in $(cat temp2); do i2e.sh -e $w; done | more # A command line to emulate the 'for' loop in programming languages for i in $(seq 7); do echo hello; done # Summarize disk usage for the current directory. That is, do not # display disk usage statistics for each sub-directory. du -s . # The command line below takes an example sentence and turns it into # a word-for-word translation in spanish using the i2e program # It prints the original phrase and its translation of the following # line. Words which are not in the dictionary are rendered as # [???] s="hello how are you"; echo $s; for v in $(echo $s); do i2e.sh -e $v | sed "/^ *$/d" | head -1 | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | tr '\n' ' '; done; echo "" # This command is similar to the above but does the translation process # for each line in a named file, in the case the file called # tutor-phrase-help.txt. for line in $(cat tutor-phrase-help.txt | tr ' ' '#'); do s=$(echo $line | tr '#' ' '); echo $s; for v in $(echo $s); do i2e.sh -e $v | sed "/^ *$/d" | head -1 | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | tr '\n' ' '; done; echo ""; done | more # A slightly improved version of the same. This is beginning to become # slow for the shell to process. This version displays only one # equivalent word for each english word. for line in $(cat tutor-phrase-help.txt | sed "/^[^a-zA-Z]*$/d" | tr ' ' '#'); do s=$(echo $line | tr '#' ' '); echo $s; for v in $(echo $s | tr '[A-Z]' '[a-z]' | sed "s/[^a-z]/ /g"); do i2e.sh -e $v | sed "/^ *$/d" | head -1 | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | sed 's/A (abrev\. de amperio)/uno/i' | tr '\n' ' '; done; echo ""; echo "+++++++++"; done | more # This version of the translator displays every alternative meaning # for the target english word and encloses the sets of meanings in # triangle brackets. The display format is really not very clear for line in $(cat tutor-phrase-help.txt | sed "/^[^a-zA-Z]*$/d" | tr ' ' '#'); do s=$(echo $line | tr '#' ' '); echo $s; for v in $(echo $s | tr '[A-Z]' '[a-z]' | sed "s/[^a-z]/ /g"); do printf '['; i2e.sh -e $v | sed "/^ *$/d" | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | sed 's/A (abrev\. de amperio)/uno/i' | tr '\n' ','; printf '] '; done; echo ""; echo "+++++++++"; done | more # This is a much better layout format, displaying one alternative for # a give english word, assuming that the alternative is available, # and displaying the alternative on a different line. for line in $(cat tutor-phrase-help.txt | sed "/^[^a-zA-Z]*$/d" | tr ' ' '#'); do s=$(echo $line | tr '#' ' '); echo $s; for v in $(echo $s | tr '[A-Z]' '[a-z]' | sed "s/[^a-z]/ /g"); do i2e.sh -e $v | sed "/^ *$/d" | head -1 | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | sed 's/A (abrev\. de amperio)/uno/i' | sed "s/^ *//g" | sed "s/ *$//g" | tr '\n' ' '; done; echo ""; for v in $(echo $s | tr '[A-Z]' '[a-z]' | sed "s/[^a-z]/ /g"); do i2e.sh -e $v | sed "/^ *$/d" | head -2 | tail -1 | sed "s/not found in.*/[???]/gi" | sed "s/^[^:]*://" | sed 's/A (abrev\. de amperio)/uno/i' | sed "s/^ *//g" | sed "s/ *$//g" | tr '\n' ' '; done; echo ""; echo "=============================="; done | more # A pipe to set up an alias (short command) to print out the current # date and time in Barcelona, Spain alias thetime='lynx --dump www.timeanddate.com/worldclock/city.html?n=31 | grep -A4 "Barcelona, Spain"' # Sets up an alias to print a description of programs (normally executable) # which a contained in the various bin directories of the linux system # This gives you a very approximate idea of what commands are available # on the current computer system. alias desc='for i in $(locate /bin/); do whatis $(basename $i); done | grep -v "nothing appropriate"' #-- Here is a script version of the translator command line above. #-- Ella_Associates:~/mjb# cat tradoos.sh #-- A script to provide what is called a "gist" translation of a text file #-- It is called tradoos because apparently there is some translating #-- software called 'trados' for line in $(cat $1 | sed "/^[^a-zA-Z]*$/d" | tr ' ' '#') do s=$(echo $line | tr '#' ' ') echo $s #-- process each word in the line, reducing to lower case #-- and removing puntuation for v in $(echo $s | tr '[A-Z]' '[a-z]' | sed "s/[^a-z]/ /g") do i2e.sh -e $v | sed "/^ *$/d" \ | head -1 | sed "s/not found in.*/[???]/gi" \ | sed "s/^[^:]*://" \ | sed 's/A (abrev\. de amperio)/uno/i' \ | tr '\n' ' ' done echo "" echo "+++++++++" done #-- Another idea for the translator would be to produce #-- html layout with select boxes containing alternate #-- translations of a particular word #-- Also, by removing the s, er, ed, ing suffixes is would #-- be possible to match more words.