I'm trying to make a program that reads lines from a file starting at the line that read "bindings: {" and ending with"}", removing colons, commas, and single quotes along the way. Ultimately, I want to save the contents of these lines into different arrays based on what the second field contains.
declare -a text_binding_arr
gawk '/(bindings: \{)/, /\}/ {
gsub(/:/, "")
gsub(/\047/, "")
gsub(/\054/, "")
switch($2) {
case /=/:
two_way_binding_arr+=( "$1" )
break
case /\@/:
text_binding_arr+=( "$1" )
break
case /</:
one_way_binding_arr+=( "$1" )
break
case /&/:
method_binding_arr+=( "$1" )
break
default:
break
}
}' test/components/temp."$COMPO".module.js
for a in text_binding_arr; do echo "${text_binding_arr[@]\n}"; done
Input
templateUrl: 'components/textfield/textfield.template.html',
controller: bltTextfieldController,
bindings: {
model: '=',
name: '@',
label: '@',
type: '@',
minlength: '<',
maxlength: '<',
min: '<',
max: '<',
change: '&',
rows: '<',
validate: '<',
required: '<',
autofocus: '<',
autocomplete: '<',
autocorrect: '<',
spellcheck: '<',
disabled: '<',
pattern: '@',
tabindex: '<',
step: '<'
}
};
Expected Output
name
label
type
pattern
What works:
- finding the pattern (i.e. "bindings: }"}
- the substitutions
- printing the array
What doesn't work:
- switch structure with special characters
- adding elements to end of arras
It currently outputs a blank line.
I am using Cygwin on Windows 10, if that matters, and the rest of my script works beautifully. This is part of a larger bash script.
I know other people have asked questions about adding to the end of an array in Gawk before here, but none of those solutions are working for me. I have tried all of this and this didn't really apply to me. Any help?