Remove whitespace from all array elements

SamFlynn

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!

kos

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to remove all next elements from array in javascript or lodash

분류에서Dev

How to remove whitespace in array element?

분류에서Dev

Using recursive function to remove all duplicated array elements

분류에서Dev

Remove all child elements from table except for first?

분류에서Dev

Recursively remove elements from nested array looking for a specific value

분류에서Dev

Remove element from array then shift other elements over

분류에서Dev

Postgres get all elements where value matches from jsonb array

분류에서Dev

Remove object from array

분류에서Dev

Appending to array replaces all elements in the array

분류에서Dev

Remove all hyperlinks from a spreadsheet

분류에서Dev

Remove all characters from the string

분류에서Dev

How to remove a simple specific key value pair from all objects inside an array

분류에서Dev

Pick specific elements from array

분류에서Dev

Determine if expression is true for all array elements in Ruby

분류에서Dev

PHP List All Combination of Elements of Array

분류에서Dev

Remove elements from lists based on condition

분류에서Dev

Remove object from JSON array

분류에서Dev

How to find the number of elements in the array that are bigger than all elements after it?

분류에서Dev

Remove elements from range and copy removed elements to new range

분류에서Dev

Remove array key from multidimensional array

분류에서Dev

Remove all elements with specific class if clicked outside of specific element

분류에서Dev

remove all duplicate class elements, except for the first one

분류에서Dev

How to get all elements from an atomFamily in recoil?

분류에서Dev

Jquery Autocomplete from json list all elements

분류에서Dev

Remove all blocks from Magento template

분류에서Dev

remove all empty values from url string

분류에서Dev

Get array of unique elements from Mysql

분류에서Dev

math operations from array elements in bash script

분류에서Dev

jQuery - Select elements by value from array of values

Related 관련 기사

  1. 1

    How to remove all next elements from array in javascript or lodash

  2. 2

    How to remove whitespace in array element?

  3. 3

    Using recursive function to remove all duplicated array elements

  4. 4

    Remove all child elements from table except for first?

  5. 5

    Recursively remove elements from nested array looking for a specific value

  6. 6

    Remove element from array then shift other elements over

  7. 7

    Postgres get all elements where value matches from jsonb array

  8. 8

    Remove object from array

  9. 9

    Appending to array replaces all elements in the array

  10. 10

    Remove all hyperlinks from a spreadsheet

  11. 11

    Remove all characters from the string

  12. 12

    How to remove a simple specific key value pair from all objects inside an array

  13. 13

    Pick specific elements from array

  14. 14

    Determine if expression is true for all array elements in Ruby

  15. 15

    PHP List All Combination of Elements of Array

  16. 16

    Remove elements from lists based on condition

  17. 17

    Remove object from JSON array

  18. 18

    How to find the number of elements in the array that are bigger than all elements after it?

  19. 19

    Remove elements from range and copy removed elements to new range

  20. 20

    Remove array key from multidimensional array

  21. 21

    Remove all elements with specific class if clicked outside of specific element

  22. 22

    remove all duplicate class elements, except for the first one

  23. 23

    How to get all elements from an atomFamily in recoil?

  24. 24

    Jquery Autocomplete from json list all elements

  25. 25

    Remove all blocks from Magento template

  26. 26

    remove all empty values from url string

  27. 27

    Get array of unique elements from Mysql

  28. 28

    math operations from array elements in bash script

  29. 29

    jQuery - Select elements by value from array of values

뜨겁다태그

보관