2 #read file sections - key word to key word
3 #use -- param if -* pattern
9 if [ "$parm" = "-P" ]; then
10 [ -z "$grep_param" ] && grep_param
="-P" || grep_param
="$grep_param -P"
16 if [ "$parm" = "-I" ]; then
17 [ -z "$grep_param" ] && grep_param
="-i" || grep_param
="$grep_param -i"
23 if [ "$parm" = "-o" ]; then
30 if [ "$parm" = "-d" ]; then
37 if [ "$parm" = "-u" ]; then
44 if [ "$parm" = "-c" ]; then
51 if [ "$parm" = "-e" ]; then
58 if [ "$parm" = "-x" ]; then
65 if [ "$parm" = "-q" ]; then
72 if [ "$parm" = "-2" ]; then
79 if [ "$parm" = "-s" ]; then
86 if [ "$parm" = "-1" ]; then
93 if [ "$parm" = "-z" ]; then
100 if [ "$parm" = "-i" ]; then
107 if [ "$parm" = "-n" ]; then
114 #use -- param if -* pattern
115 if [ "$parm" = "--" ]; then
119 if [ -z "$setparam" ]; then
120 if [ "$parm" != "$(echo "$parm" | sed 's%^-%%')" ]; then
121 echo "$0: No such param"
129 if [ $exclude ]; then
131 [ "$excludepatt" != "${excludepatt#-}" ] && excludepatt
="\\$excludepatt"
135 if [ $check_pattern ]; then
137 [ "$chkpatt" != "${chkpatt#-}" ] && chkpatt
="\\$chkpatt"
142 [ ! -f "$file" ] && exit 1
145 [ "$grep1" != "${grep1#-}" ] && grep1
="\\$grep1"
148 [ "$grep2" != "${grep2#-}" ] && grep2
="\\$grep2"
150 if [ $start_line_num ]; then
151 if echo "$grep1" |
grep -q "[^[:digit:]]"; then
152 echo "$0: Parameter not numeric"
161 if [ $start_line_num ]; then
164 if [ $longest ]; then
165 NUMS
=$
(grep $@
-n "$grep1" "$file" | cut
-d : -f 1 |
head -n 1)
167 NUMS
=$
(grep $@
-n "$grep1" "$file" | cut
-d : -f 1)
172 if [ $longest ]; then
173 if [ $find_next_line ]; then
175 ENDNUMA
=$
(tail -n +$j "$file" |
grep $@
-n "$grep2" | cut
-d : -f 1 |
tail -n 1)
176 [ ! -z "$ENDNUMA" ] && ENDNUMA
=$
(expr $ENDNUMA + 1)
178 ENDNUMA
=$
(tail -n +$i "$file" |
grep $@
-n "$grep2" | cut
-d : -f 1 |
tail -n 1)
181 if [ $find_next_line ]; then
183 ENDNUMA
=$
(tail -n +$j "$file" |
grep $@
-n "$grep2" | cut
-d : -f 1 |
head -n 1)
184 [ ! -z "$ENDNUMA" ] && ENDNUMA
=$
(expr $ENDNUMA + 1)
186 ENDNUMA
=$
(tail -n +$i "$file" |
grep $@
-n "$grep2" | cut
-d : -f 1 |
head -n 1)
189 #if [ ! -z "$ENDNUMA" ]; then
190 #echo "$i - $ENDNUMA - $(expr $i - 1 + $ENDNUMA)"
192 #echo "$i - 1 - $(expr $i - 1 + 1)"
195 if [ $exit_nomatch ]; then
196 [ -z "$ENDNUMA" ] && continue
199 if [ -z "$ENDNUMA" ]; then
201 if ! [ $dont_print_file ]; then
202 if [ $print_num ]; then
209 if ! [ $dont_print_file ]; then
210 if [ $print_num ]; then
218 if [ "$ENDNUMA" = "1" ]; then
219 if [ $print_till_end ]; then
220 if [ $print_inner ]; then
221 if [ $check_pattern ]; then
222 if [ $inv_chkpatt ]; then
223 if ! tail -n +$
(expr $i + 1) "$file" |
grep $@
-q "$chkpatt"; then
224 if [ $exclude ]; then
225 tail -n +$
(expr $i + 1) "$file" |
grep $@
-v "$excludepatt"
227 tail -n +$
(expr $i + 1) "$file"
231 if tail -n +$
(expr $i + 1) "$file" |
grep $@
-q "$chkpatt"; then
232 if [ $exclude ]; then
233 tail -n +$
(expr $i + 1) "$file" |
grep $@
-v "$excludepatt"
235 tail -n +$
(expr $i + 1) "$file"
240 if [ $exclude ]; then
241 tail -n +$
(expr $i + 1) "$file" |
grep $@
-v "$excludepatt"
243 tail -n +$
(expr $i + 1) "$file"
246 #tail -n +$(expr $i + 1) "$file"
248 if [ $check_pattern ]; then
249 if [ $inv_chkpatt ]; then
250 if ! tail -n +$i "$file" |
grep $@
-q "$chkpatt"; then
251 if [ $exclude ]; then
252 tail -n +$i "$file" |
grep $@
-v "$excludepatt"
258 if tail -n +$i "$file" |
grep $@
-q "$chkpatt"; then
259 if [ $exclude ]; then
260 tail -n +$i "$file" |
grep $@
-v "$excludepatt"
267 if [ $exclude ]; then
268 tail -n +$i "$file" |
grep $@
-v "$excludepatt"
276 if [ $check_pattern ]; then
277 if [ $inv_chkpatt ]; then
278 if ! tail -n +$i "$file" |
head -n 1 |
grep $@
-q "$chkpatt"; then
279 if [ $exclude ]; then
280 tail -n +$i "$file" |
head -n 1 |
grep $@
-v "$excludepatt"
282 tail -n +$i "$file" |
head -n 1
286 if tail -n +$i "$file" |
head -n 1 |
grep $@
-q "$chkpatt"; then
287 if [ $exclude ]; then
288 tail -n +$i "$file" |
head -n 1 |
grep $@
-v "$excludepatt"
290 tail -n +$i "$file" |
head -n 1
295 if [ $exclude ]; then
296 tail -n +$i "$file" |
head -n 1 |
grep $@
-v "$excludepatt"
298 tail -n +$i "$file" |
head -n 1
301 #tail -n +$i "$file" | head -n 1
302 #sed -n "${i}p" "$file"
305 if [ $print_inner ]; then
306 if [ $check_pattern ]; then
307 if [ $inv_chkpatt ]; then
308 if ! tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2) |
grep $@
-q "$chkpatt"; then
309 if [ $exclude ]; then
310 tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2) |
grep $@
-v "$excludepatt"
312 tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2)
316 if tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2) |
grep $@
-q "$chkpatt"; then
317 if [ $exclude ]; then
318 tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2) |
grep $@
-v "$excludepatt"
320 tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2)
325 if [ $exclude ]; then
326 tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2) |
grep $@
-v "$excludepatt"
328 tail -n +$
(expr $i + 1) "$file" |
head -n $
(expr $ENDNUMA - 2)
331 #tail -n +$(expr $i + 1) "$file" | head -n $(expr $ENDNUMA - 2)
333 if [ $print_wo_last ]; then
334 if [ $check_pattern ]; then
335 if [ $inv_chkpatt ]; then
336 if ! tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1) |
grep $@
-q "$chkpatt"; then
337 if [ $exclude ]; then
338 tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1) |
grep $@
-v "$excludepatt"
340 tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1)
344 if tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1) |
grep $@
-q "$chkpatt"; then
345 if [ $exclude ]; then
346 tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1) |
grep $@
-v "$excludepatt"
348 tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1)
353 if [ $exclude ]; then
354 tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1) |
grep $@
-v "$excludepatt"
356 tail -n +$i "$file" |
head -n $
(expr $ENDNUMA - 1)
359 #tail -n +$i "$file" | head -n $(expr $ENDNUMA - 1)
361 if [ $check_pattern ]; then
362 if [ $inv_chkpatt ]; then
363 if ! tail -n +$i "$file" |
head -n $ENDNUMA |
grep $@
-q "$chkpatt"; then
364 if [ $exclude ]; then
365 tail -n +$i "$file" |
head -n $ENDNUMA |
grep $@
-v "$excludepatt"
367 tail -n +$i "$file" |
head -n $ENDNUMA
371 if tail -n +$i "$file" |
head -n $ENDNUMA |
grep $@
-q "$chkpatt"; then
372 if [ $exclude ]; then
373 tail -n +$i "$file" |
head -n $ENDNUMA |
grep $@
-v "$excludepatt"
375 tail -n +$i "$file" |
head -n $ENDNUMA
380 if [ $exclude ]; then
381 tail -n +$i "$file" |
head -n $ENDNUMA |
grep $@
-v "$excludepatt"
383 tail -n +$i "$file" |
head -n $ENDNUMA
392 [ $close_end ] && echo "+++"