See this page in (approximate): Español| Français| Italiano| Deutsch| Português

Some Bash Shell Incantations

[make a comment about (or add to) this document]

1. DESCRIPTION
2. INCANTATIONS

  
1. DESCRIPTION [TOC]
  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.

2. INCANTATIONS [TOC]

for i in wordlist*; do cp $i $(echo $i | sed "s/wordlist/gencat-phraselist/g"); done
   This is a line to rename a group of files which all have similar names
  
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/^[ ]*\*\(.*\)/<item value = \"\1\">/g;x;G;s/^<item value = \"[^\n]*/<\/item>/;}" | 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.


BACK TO THE TABLE OF CONTENTS
If you wish, you may add a comment, suggestion or other contribution which will appear at the end of this document.
Any input you make is greatly appreciated.


Your Comment (or other contribution to this document)


Your Name [OPTIONAL BUT NICE]


See this page in (approximate): Español| Français| Italiano| Deutsch| Português
Hosted by www.Geocities.ws

1