I have a array called arrayvar
, which is being defined as
arrayvar=( $(awk '/'"$vovar"'/,/}/ {gsub("'"$vovar"'"," "); gsub("}"," "); gsub("{"," ");gsub(","," ");print}' temp1 | tr -d '\n' | sed 's/^[ \t]*//' | sed 's/[ \t]*$//') )
with
vovar=VARIABLES
My temp file has some variables which I am grabbing using the above command and the tr
sed
commands to remove spaces.
TEMP file
ENTERPRISE eMylexRaidEventInformation VARIABLES { a9EventCode, a9ControllerNumber, a9ChannelNumber, a9TargetNumber, a9LunNumber, a9EventTimeStamp } DESCRIPTION "device became online." --#SUMMARY "[Event %d ctl %d chn %d tgt %d lun %d Time %d :] device became online." --#ARGUMENTS {0,1,2,3,4,5} --#SEVERITY INFORMATIONAL --#TIMEINDEX 5 --#STATE OPERATIONAL ::= 1
When I run this command only arrayvar[0]
is stripped of its values like this:
echo "${arrayvar[0]}" a9EventCode echo "${arrayvar[1]}" a9ControllerNumber echo "${arrayvar[2]}" a9ChannelNumber echo "${arrayvar[3]}" a9TargetNumber
Any help will be appreciated. Thanks!
{
and}
as array elements ?{ }
brackets afterVARIABLES
. Warning , those strings may vary, they could all be in a single line, multiple strings in multiple line, only one string with in the{}
and one string in one line (like the example above). TheDESCRIPTION
after}
may or maynot be there. Same goes forENTERPRISE
. Only thing that separates the strings in the{ }
are,
. Which may not be there when we have only one string between { }.a9EventCode, a9ControllerNumber
could be in a single line ? what would be the separator then ? also add some practical examples to your question you have mentioned in the comment..