next end up end toc toc Src mail

all, section 15.2.

15.2.  Appendix: Sed

See also vi, or sed

$ echo 'a b' | sed 's/\(.*\) \(.*\)/\2 \1/'
b a

$ date | sed 's/.*\(..:..:..\).*/It is now \1/'
It is now 17:31:42

$ expr "`date`" : '.*\(..:..:..\)'
8:32:21

$ echo It is now `expr "\`date\`" : '.*\(..:..:..\)'`
It is now 17:35:05

$ set `date`
$ echo $1 "---" $2
Mon --- Apr
$ date
Mon Apr  6 16:19:46 EDT 1998
$
$ set `date`
$ echo It is now $4
It is now 17:36:48

Examples:

1.

 1      #!/bin/sh
 2      
 3      echo "> "
 4      while read x
 5      do
 6            case $x
 7              in *a)          echo "ends with a"
 8              ;; *b)          echo "ends with b"
 9              ;; c*b)         echo "ends with b"
10            esac
11            echo "> "
12      done
13      

2.
 1      #!/bin/sh
 2      
 3      cat html_files          |
 4      while read x
 5      do
 6              cp $x $x.copy
 7              echo $x
 8              cat $x.copy             |
 9              sed 's/bischof@informatik.uni-osnabrueck.de/hpb@cs.rit.edut/g'   > $x
10      done
11      
12      exit 0

2.
 1      #!/bin/sh
 2      #
 3      echo "-------------"
 4      echo "Be carefull!."
 5      echo "-------------"
 6      echo
 7      
 8      cat create_to_link_end_of_world                 |       \
 9      while read f link
10      do
11              echo "Fix $f $link" > /dev/tty
12              read x < /dev/tty
13              echo $x
14              if [ $x = "y" ]
15              then
16                      cp $f $f.was
17                      cat $f.was | sed "s-$link-../../Images/end_off_the_world.gif-"  > $f
18              fi
19      done

3.
 1      #!/bin/sh
 2      #
 3      TOP_DIR=/home/bischof/public_html/Man/_Man_SunOS_4.1.3_html/html3
 4      TOP_DIR=/home/bischof/public_html/Man/
 5      TOP_DIR=/home/bischof/public_html/Man/_Man_NeXT_html/html1/
 6      TOP_DIR=/home/bischof/public_html/Man/_Man_Gnu_html
 7      
 8      case $#
 9              in      0)      break
10              ;;      1)      TOP_DIR="$1"
11              ;;      *)      echo "`basname $0` [dir]"
12      esac
13      
14      cd $TOP_DIR
15      find . -type f -name '*html' -print     |
16      while read FILE
17      do
18              (
19              cd `dirname $FILE`
20              LOCAL_FILE=`basename $FILE`
21              egrep '<a href=".*a>' $LOCAL_FILE       |       
22              while read LINK 
23              do
24                      LINK_FILE=`echo $LINK                   |
25                              sed 's/.*<a href="//'           |
26                              sed 's/".*//'`
27                      if [ ! -f  $LINK_FILE ]
28                      then
29                              echo "$FILE: $LINK_FILE doesn't exist."
30                      fi
31              done
32              )
33      done
34      
35      exit 0

Example:

% delete_dead_links 
 ./html1/addftinfo.1.html: ../html5/font.5.html doesn't exist.
 ./html1/bash.1.html: ../html3/isatty.3.html doesn't exist.
 ./html1/bison.1.html: ../html1/yacc.1.html doesn't exist.
 ./html1/bison.1.html: ../html1/yacc.1.html doesn't exist.


back end up end toc toc Src mail


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 08/May/98 (11:53)