-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaeareq
More file actions
executable file
·54 lines (47 loc) · 1.6 KB
/
aeareq
File metadata and controls
executable file
·54 lines (47 loc) · 1.6 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
#!/bin/bash
#if [[ "$1" == "sug" ]]
#then
# sed -i.bak2 '/-------/r'<(grep SUGGESTED REPLICATION.md | sed 's/>/-/') REPLICATION.md
#fi
force=FALSE
if [[ "$1" == "force" ]]
then
force=TRUE
shift
fi
actionitems=$(grep -n 'action items go here' REPLICATION.md|awk -F: '{ print $1}')
if [[ -z $actionitems && $force == FALSE ]]
then
echo "The report does not contain a line with "
echo "----action items go here----"
echo "To prevent errors, refusing to do anything."
echo "If you wish to nevertheless let this script work,"
echo "append the argument 'force' when calling the script,"
echo "or add the line"
echo "----action items go here----"
echo "back into the report."
echo "After successfully inserting any REQUIRED and"
echo "SUGGESTED tags, the line will be deleted again"
echo ""
echo "$0 force"
exit 2
else
# grab them
grep -E "REQUIRED|SUGGESTED" REPLICATION.md| grep -E "^>|^-" | sort|uniq | sed 's/>/- [ ]/'> REPLICATION.tmp
# count them
count=$(cat REPLICATION.tmp | wc -l)
# insert after marker using awk for robust multi-line insertion
awk -v marker="action items go here" 'NR==FNR{a[NR]=$0;next} {print} $0~marker{for(i=1;i<=length(a);i++) print a[i]}' REPLICATION.tmp REPLICATION.md > REPLICATION.new && mv REPLICATION.new REPLICATION.md
result=$?
case $result in
0)
# delete the marker line
sed -i.bak "/action items go here/d" REPLICATION.md
echo ":: REPLICATION.md successfully updated."
echo ":: ${count} tags found, sorted, unique"
;;
*)
echo "::: An error was produced: $result"
;;
esac
fi