-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_many.sh
More file actions
executable file
·77 lines (58 loc) · 1.25 KB
/
replace_many.sh
File metadata and controls
executable file
·77 lines (58 loc) · 1.25 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# arguments of the form
# <token> <value 1> <value 2> ... <value N>
# the template file is passed in through standard in
# template file should have token <token>
function usage {
cat <<EOF
Usage: replace_many.sh TOKEN VALUE...
Creates N copies of the IOR template passed in through
standard input, each having replaced all instances of
TOKEN with each VALUE given.
For example:
ior.in:
IOR START
api=POSIX
segmentCount=10
blockSize=foo
transferSize=foo
testFile=temp.dat
RUN
IOR STOP
replace_many.sh foo 8 16 32 < ior.in
produces the output:
IOR START
api=POSIX
segmentCount=10
blockSize=8
transferSize=8
testFile=temp.dat
RUN
api=POSIX
segmentCount=10
blockSize=16
transferSize=16
testFile=temp.dat
RUN
api=POSIX
segmentCount=10
blockSize=32
transferSize=32
testFile=temp.dat
RUN
IOR STOP
EOF
exit 1
}
token=$1
[[ $token == "" ]] && usage
shift
[[ $1 == "" ]] && usage
tempfile=$(mktemp)
cat | sed -r "/IOR *(START|STOP)/ d" > $tempfile
echo IOR START
for value in $@ ; do
sed "s!$token!$value!g" $tempfile
done
echo IOR STOP
rm $tempfile