Description
- A line is said to be `matched' if it contains a substring matched
a given regex.
- In the following example, we want to get the 3rd, the 5th, 8th, and the
9th lines who are matched `PATH'. The case distinctions are ignored in
this example.
|
| Raw Input
|
| Desired Output
| (1)pathmunge () {
if ! echo $(2)PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
(3)PATH=$PATH:$1
else
(4)PATH=$1:$PATH
fi
fi
}
if [ "$EUID" = "0" ]; then
(5)pathmunge /sbin
(6)pathmunge /usr/sbin
(7)pathmunge /usr/local/sbin
else
(8)pathmunge /usr/local/sbin after
(9)pathmunge /usr/sbin after
(10)pathmunge /sbin after
fi
HOSTNAME=`/bin/hostname 2>/dev/null`
HISTSIZE=1000
export (11)PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
unset (12)pathmunge
|
| (3)PATH=$PATH:$1
(5)pathmunge /sbin
(8)pathmunge /usr/local/sbin after
(9)pathmunge /usr/sbin after
|
|
Script and Comments
Script1 [ 1] /PATH/I!d
[ 2] G
[ 3] s/$/#/
[ 4] /\n(#{3}|#{5}|#{8}|#{9})$/P
[ 5] s/^[^\n]*\n//
[ 6] h
[ 7] d
|
Script2 [ 1] /PATH/I!d
[ 2] G
[ 3] s/$/#/
[ 4] /\n#{9}$/{
[ 5] s/\n.*//
[ 6] q
[ 7] }
[ 8] /\n(#{3}|#{5}|#{8})$/P
[ 9] s/^[^\n]*\n//
[10] h
[11] d
| |