-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstring-replacer.sh
73 lines (64 loc) · 1.59 KB
/
string-replacer.sh
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
# Raymond Kiu [email protected]
usage () {
echo ""
echo "This program replaces strings in any file"
echo ""
echo "Usage: $0 [options] -r oldlist newlist file > NEWFILENAME"
echo "Options:"
echo " -r replace strings and exit"
echo " -h print usage and exit"
echo " -a print author and exit"
echo " -v print version and exit"
}
version () { echo "version 0.1";}
author () { echo "Author: Raymond Kiu [email protected]";}
listA=$2
listB=$3
FILE=$4
replace () {
if [ -e "$listA" ];then
:
else
echo "$listA file does not seem to exist. Program will now exit."
exit 1
fi
if [ -e "$listB" ];then
:
else
echo "$listB file does not seem to exist. Program will now exit."
exit 1
fi
if [ -e "$FILE" ];then
:
else
echo "$FILE file does not seem to exist. Program will now exit."
exit 1
fi
paste -d : $listA $listB | sed 's/\([^:]*\):\([^:]*\)/s%\1%\2%/' > $FILE-sed.script;
sed -f $FILE-sed.script $FILE
rm $FILE-sed.script
exit 0
}
# Call options
while getopts ':rhav' opt;do
case $opt in
r) replace; exit;;
h) usage; exit;;
a) author; exit;;
v) version; exit;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
:) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
*) echo "Unimplemented option: -$OPTARG" >&2; exit 1;;
esac
done
# Skip over processed options
shift "$((OPTIND-1))"
# check for mandatory positional parameters, only 1 positional argument will be checked
if [ $# -lt 3 ]; then
echo "Missing optional argument or positional argument"
echo ""
echo "Options: ./sequence-stats -h"
echo ""
echo ""
exit 1
fi