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!
You could use this:
var=( $(< input awk '/VARIABLES {/, /}/ {if ($0~/VARIABLES/||$0~/}/) next; else gsub(/[ ,]/, "", $0); print}') )
VARIABLES {
와 일치하는 레코드 사이의 모든 레코드를 인쇄 }
하여 모든
및 ,
문자를 제거 합니다.그러나 mapfile
값을 배열에 저장하기 위해 이중 포크 대신 및 단일 포크를 사용 하고 싶습니다 .
mapfile var < <(< input awk '/VARIABLES {/, /}/ {if ($0~/VARIABLES/||$0~/}/) next; else gsub(/[ ,]/, "", $0); print}')
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다