blob: c9a460fcd4fee0c7a37e9a1edc2e95dc3106dc72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#!/bin/echo Run scripts/test.sh
#testing "name" "command" "result" "infile" "stdin"
# Exploring the wonders of sed addressing modes
testing '' 'sed -n 1p' "one\n" "" "one\ntwo\nthree"
testing '' 'sed 2p' "one\ntwo\ntwo\nthree" "" "one\ntwo\nthree"
testing '' 'sed -n 2p' "two\n" "" "one\ntwo\nthree"
# Fun with newlines!
testing '' 'sed -n 3p' "three" "" "one\ntwo\nthree"
testing 'sed as cat' 'sed ""' "one\ntwo\nthree" "" "one\ntwo\nthree"
testing 'sed -n $p' 'sed -n \$p' "three" "" "one\ntwo\nthree"
testing 'sed as cat #2' "sed -n '1,\$p'" "one\ntwo\nthree" "" "one\ntwo\nthree"
testing '' 'sed -n 1,2p' "one\ntwo\n" "" "one\ntwo\nthree"
testing '' 'sed -n 2,3p' "two\nthree" "" "one\ntwo\nthree"
testing '' 'sed -n 2,1p' "two\n" "" "one\ntwo\nthree"
testing 'sed -n $p (2 input)' 'sed -n \$p - input' "four\n" "four\n" \
"one\ntwo\nthree"
# More fun with newlines! The missing \n is now _back_
testing 'prodigal newline' "sed -n '1,\$p' - input" "one\ntwo\nthree\nfour\n" \
"four\n" "one\ntwo\nthree"
testing 'no input means no last line' "sed '\$a boing'" "" "" ""
testing 'sed 3p - input' "sed -n 3p" "three" "four\n" "one\ntwo\nthree"
testing 'sed match \t tab' "sed -n '/\t/p'" "\tx\n" "" "\tx\n"
testing 'sed match t delim disables \t tab' "sed -n '\t\txtp'" "" "" "\tx\n"
testing 'sed match t delim makes \t literal t' \
"sed -n '\t\txtp'" "tx\n" "" "tx\n"
testing 'sed match n delim' "sed -n '\n\txnp'" "\tx\n" "" "\tx\n"
testing 'end match does not check starting match line' \
"sed -n '/two/,/two/p'" "two\nthree" "" "one\ntwo\nthree"
testing 'end match/start match mixing number/letter' \
"sed -n '2,/two/p'" "two\nthree" "" "one\ntwo\nthree"
testing 'sed num then regex' 'sed -n 2,/d/p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
testing 'sed regex then num' 'sed -n /b/,4p' 'b\nc\nd\n' '' 'a\nb\nc\nd\ne\nf\n'
testing 'sed multiple regex address match' 'sed -n /on/,/off/p' \
'bone\nturtle\scoff\ntron\nlurid\noffer\n' "" \
'zap\nbone\nturtle\scoff\nfred\ntron\nlurid\noffer\nbecause\n'
testing 'sed regex address overlap' 'sed -n /on/,/off/p' "on\nzap\noffon\n" "" \
'on\nzap\noffon\nping\noff\n'
testing "sed aci" \
"sed -e '3a boom' -e '/hre/i bang' -e '3a whack' -e '3c bong'" \
"one\ntwo\nbang\nbong\nboom\nwhack\nfour\n" "" \
"one\ntwo\nthree\nfour\n"
testing 'sed prodigaler newline' 'sed -e a\\ -e woo' 'one\nwoo\n' '' 'one'
testing 'sed newline staying away' 'sed s/o/x/' 'xne\ntwx' '' 'one\ntwo'
# Why on _earth_ is this not an error? There's a \ with no continuation!
testing 'sed what, _really_?' 'sed -e a\\ && echo yes really' \
'one\nyes really\n' '' 'one\n'
|