b220a2062a7a46df563f66066ec6973751a446a6
3 # Date: 2020-02-15T22:23Z
5 # Author: Steven Baltakatei Sandoval
7 # Description: `bkgettext` prints text between and including two
11 # $ bkgettext [ -s tagStart ] [ -e tagEnd ] [ -f file ]
13 echoerr
() { echo "$@" 1>&2; } # function for outputing to stderr; see [3]
14 vc
() { [ "$OPTION_VERBOSE" == "true" ] && return 0 ||
return 1; } # returns true if verbose mode active
15 print_help
() { echoerr
"Usage: [ -s tagStart ] [ -e tagEnd ] [ -f file ] "; } # print help
17 # echoerr "process_inputs() \$1:""===""$1""==="
18 # echoerr "process_inputs() \$2:""===""$2""==="
19 # echoerr "process_inputs() \$3:""===""$3""==="
20 # echoerr "process_inputs() \$4:""===""$4""==="
21 # echoerr "process_inputs() \$5:""===""$5""==="
22 # echoerr "process_inputs() \$6:""===""$6""==="
23 # echoerr "process_inputs() \$7:""===""$7""==="
24 # echoerr "process_inputs() \$8:""===""$8""==="
26 while getopts "vhs:e:f:" options_array
; do
27 case "${options_array}" in
30 vc
&& echoerr
"DEBUG:Verbose mode active."
37 vc
&& echoerr
"DEBUG:tagStart:""$tagStart"
41 vc
&& echoerr
"DEBUG:tagEnd:""$tagEnd"
44 [ ! -f ${OPTARG} ] && echoerr
"ERROR: Invalid file name provided." && exit 1;
46 vc
&& echoerr
"DEBUG:fileInput:""$fileInput"
58 process_inputs
"$@" # Define variables: tagStart tagEnd fileInput
59 # echoerr "main() \$1:""===""$1""==="
60 # echoerr "main() \$2:""===""$2""==="
61 # echoerr "main() \$3:""===""$3""==="
62 # echoerr "main() \$4:""===""$4""==="
63 # echoerr "main() \$5:""===""$5""==="
64 # echoerr "main() \$6:""===""$6""==="
65 # echoerr "main() \$7:""===""$7""==="
66 # echoerr "main() \$8:""===""$8""==="
67 # echoerr "main() \$tagStart:""===""$tagStart""==="
68 # echoerr "main() \$tagEnd:""===""$tagEnd""==="
69 # echoerr "main() \$fileInput:""===""$fileInput""==="
70 #OUTPUT=$(cat "$fileInput" | awk "/$tagStart/,/$tagEnd/") # get text between and including tag lines; see [1]
71 #OUTPUT=$(cat "$fileInput" | awk "/$tagStart/{f=1;next} /$tagEnd/{f=0} f") # get text between tag lines; see [1]
72 OUTPUT
=$
(cat "$fileInput" |
awk "/$tagStart/{f=1} /$tagEnd/{f=0;print} f") # get text between and including tag lines; see [1]
76 main
"$@" # pass arguments to function "main" and execute "main" (for why `"$@"`, see [2])
77 exit 0 # exit normally
82 # [1]: How to get text between and including specified strings: https://stackoverflow.com/a/22222219
83 # [2]: How to correctly pass bash script arguments to functions: https://stackoverflow.com/a/8198970
84 # [3]: How to print text to stderr instead of stdout: https://stackoverflow.com/a/2990533