&& Some Bash Shell Incantations DESCRIPTION This file contains some 'pipe-lines' or 'incantations' that I have come up with (along with many other people) in order to do common tasks. I record them here because at times I find it a pain to try to remember or to re-invent them. There are a number of other files floating around which also have this sort of stuff in it, that I have written. INCANTATIONS * This is a line to rename a group of files which all have similar names for i in wordlist*; do cp $i $(echo $i | sed "s/wordlist/gencat-phraselist/g"); done awk '/^[^ ]/ {print toupper($0)} /^ / {print} /^$/' netbeans-tomcat-guide.txt | less An incantation to convert to upper-case all lines which do not begin with a space. Another way to do this would be with the sed 'y' command. eg sed "/^[^ ]/ y/a-z/A-Z/" But I am not sure if the y command will accept 'character sets' such as a-z or whether you need to specify individually each character. cat gencat-phraselist-en-ca.txt | sed -e "s/^[[:space:]]*//g" -e "s/[[:space:]]*$//g" -e "/\-/! h" -e "/\-/{G;s/\-\([^\-]\+\)\-\([^\n]\+\)\n\(.*\)[ ]\{4\}\(.*\)/\3 \1 \4 \2/g;}" | more This is a truly amazing pipe-line which uses the powers of sed's 'hold spaces' and 'pattern spaces' This line converts partial sentences into full sentences. An examples of the partial sentences can be found in 'gencat-phraselist-en-ca.txt'. echo '/^\n*$/{$d;N;};/\n$/ba' | sed "s/;/;|/g" | tr '|' '\n' | sed "s/\([{}]\)/|\1|/g" | tr '|' '\n' | tr -s '\n' This is a line that attempts to do what Larry Walls s2p 'sed to perl' converter. That is it attempts to convert a sed script to the syntax of another language (which may potentially be more readable). It tries to do this with a command line bash script. Its main weakness is that it needs to find a character that is not used anywhere in the sed script (in this case we use the '|' bar character) cat glossary.txt | sed "/^[ ]*\*/{s/^[ ]*\*/BEGIN:/g;x;G;s/^BEGIN:/END:/;}" | more An very nice pipe line that converts a 'title list' into a 'sectioned list' with begin and end markers for each section. The titled list might look like * item1 This is the first item. Lots of text * item 2 Another item more text. I want to convert this to a list with begin and end markers * item3 more stuff cat glossary.txt | sed "/^[ ]*\*/{s/^[ ]*\*\(.*\)//g;x;G;s/^/;}" | more This is another very interesting pipe-line once again using the power of sed 'hold spaces' in order to transform a 'titled list' into a kind of XML. The titled list items in this case start with the '*' character, but any pattern is possible. cat glossary.txt | sed "/^[ ]*\*/{x;s/[^\n]*//g;G;s/\(\n\)/--{:split:}--\1/g;}" | less A pipe-line to insert a particular tag just before a particular type of line. This is probably not the best way to do this. cat glossary.txt | csplit - "/^[ ]*\*/" "{*}" A line to split a stream based on a pattern for i in xx*; do cp $i $(grep "^[ ]*\*" $i | sed "s/^[ ]*\*/GLOSS-/g" | tr ' */' '-'); done; cat GLOSS-* | more A line which renames and outputs a set of files based on a line of text which they contain