-
Notifications
You must be signed in to change notification settings - Fork 6
/
scilab_tran_ac.sh
149 lines (114 loc) · 3.58 KB
/
scilab_tran_ac.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/bash
# ==================================================
# task 2: scilab script for abhishek pawar
# -> There are three files in each folder namely,
# 1).net
# 2).net.out
# 3).out
# ->Go to file .out
# search for text starting with .tran
# If found copy that entire statement
# else
# search for text starting with .ac
# If found copy that entire statement
# else
# do nothing
# ->Now go to .net.out
# search for text .control
# Paste statement copied in previous step in after .control in this file
# (i.e)between .control and run.
# ==================================================
# ======================= variables ===========================
SRC='files' # source folder
BCKP_EXT='.bak' # backup extension for .net.out file
TRAN='^\.tran' # pattern
AC='^\.ac' # pattern
# =================== variables end here ======================
# function to copy '.tran xxxx' line to *.net.out file
function find_dot_tran {
# grep throught *.out file for line starting with '.tran xxxx' and
# store the list of file in an array ${BUFFER_FILE[@]}
BUFFER_FILE=$(find $SRC -type f -iname "*.out" \
| xargs grep -e ${TRAN} | cut -d : -f -1)
# Go through each of file in an array ${BUFFER_FILE[@]
for FILES in ${BUFFER_FILE[@]}
do
# echo $FILES
for FILE in ${FILES[@]}
do
# store the line '.tran xxxx' in a variable $LINE
LINE=$(cat $FILE | grep -e ${TRAN})
# remove '.' (dot) from the pattern '.tran'
LINE=$(echo $LINE | sed -e 's/\.//g')
# replace .out extension with .net.out for every file
NET_OUT_FILE=$(echo $FILES | sed -e 's/'.out$'/'.net.out'/g')
# echo $LINE
# echo $NET_OUT_FILE
# check if .net.out file exist
if [ -e $NET_OUT_FILE ];
then
echo EXIST: $NET_OUT_FILE
# check if backup file .net.out.bak was created
if [ -e $NET_OUT_FILE${BCKP_EXT} ];
then
echo $NET_OUT_FILE${BCKP_EXT} EXIST
# if so, make a copy with .net.out extension
cp -v $NET_OUT_FILE${BCKP_EXT} $NET_OUT_FILE
else
echo $NET_OUT_FILE${BCKP_EXT} NOT EXIST
fi
# append the pattern 'tran xxxx' just after the line
# starting with .control in a file .net.out.
# also make a backup copy with .bak as an extension
sed -i${BCKP_EXT} -e '/^.control/a \'"$LINE"'' $NET_OUT_FILE
else
echo NOT-EXIST: $NET_OUT_FILE
fi
done
done
}
# function to copy '.ac xxxx' line to *.net.out file
function find_dot_ac {
BUFFER_FILE=$(find $SRC -type f -iname "*.out" \
| xargs grep -e ${AC} | cut -d : -f -1)
for FILES in ${BUFFER_FILE[@]}
do
# echo $FILES
for FILE in ${FILES[@]}
do
LINE=$(cat $FILE | grep -e ${AC})
LINE=$(echo $LINE | sed -e 's/\.//g')
NET_OUT_FILE=$(echo $FILES | sed -e 's/'.out$'/'.net.out'/g')
# echo $LINE
# echo $NET_OUT_FILE
if [ -e $NET_OUT_FILE ];
then
echo EXIST: $NET_OUT_FILE
# sed -e '/^${LINE}/d' $NET_OUT_FILE
if [ -e $NET_OUT_FILE${BCKP_EXT} ];
then
echo $NET_OUT_FILE${BCKP_EXT} EXIST
cp -v $NET_OUT_FILE${BCKP_EXT} $NET_OUT_FILE
else
echo $NET_OUT_FILE${BCKP_EXT} NOT EXIST
fi
sed -i${BCKP_EXT} -e '/^.control/a \'"$LINE"'' $NET_OUT_FILE
else
echo NOT-EXIST: $NET_OUT_FILE
fi
done
done
}
# sample function to remove DOT from the pattern
function sample()
{
PATTERN='.tran'
echo $PATTERN | sed -e 's/\.//g'
}
# calling functions
find_dot_ac
find_dot_tran
#sample
# ======================= TODO ===========================
# Merge both functions in to one
# ========================================================