A array is the simplest data-structure for storing items in continuously memory

learn more… | top users | synonyms

2
votes
1answer
24 views

problem with the inactive RAID 5

I have a server running ubuntu server, after a crash, I lost a Disc. Here is the output: cat /proc/mdstat Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] ...
1
vote
1answer
24 views

Adding to arrays [duplicate]

I have this script tests=() igrepy -l $1 . | while read -r line do // some processing tests+=("${second[0]}") done echo ${tests[@]} I've checked that 'second' has a result and it does, ...
1
vote
2answers
33 views

Raid array 'clean, degraded'?

Today I noticed that there are bunch of messages complaining about the RAID array (it's a software RAID10), so I started looking into it but need help because I'm unsure if I interpret the status ...
0
votes
1answer
28 views

Unique strings in bash [duplicate]

I have an array array=(src/ucode/pkgs/get_ch.c qa/tests/ucode/chktest.pl src/ucode/pkgs/get_ch.c src/profile/settings.txt src/ucode/pkgs/main_pf.c src/ucode/pkgs/get_ch.c src/ucode/pkgs/main_ch.c ...
2
votes
1answer
34 views

Array syntax with AWK

I am baffled at the response of these scripts. Trial 1: awk '{line_arr[$0] } END {for (line in line_arr) print line}' text_file Output: 1 2 3 4 Trial 2: awk '{line_arr[$0] } END {for (line in ...
0
votes
1answer
26 views

How to mark one of RAID1 disks as a spare? (mdadm)

I have a healthy and working software based RAID1 using 3 HDDs as active on my Debian machine. I want to mark one of the disks as a spare so it ends up being 2 active + 1 spare. Things like: mdadm -...
1
vote
1answer
73 views

Populate array with a sed/echo combination

I'm trying to rename multiple files containing dates. I want to split the date into year, month and day and then create a new filename in a directory tree like year/month-year/filename_yearmonthday....
1
vote
1answer
33 views

Suppress new line when Awk'ing an array

This is kind of a continuation of Awk and discarding non-matching tokens in a string? I am using Awk to filter unwanted compiler flags derived from CPU features (SunCC 12.2 cannot handle the same ...
-1
votes
1answer
50 views

Parsing a string using bash function

I'm trying to replace some codes with bash function to reuse it. So my previous codes are: #!/bin/bash set aline=" dsfsdf | fsdfff | yuhfd " set line_parsed=`echo $aline | tr '|' "\n"` echo ${...
1
vote
1answer
73 views

How to assign values of a matrix to variables in bash

I have created a 50 x 1 matrix in ubuntu as follows: #!/bin/bash declare -A matrix num_rows=1 num_columns=50 for ((n=0;n<=(($num_columns-1));n++)) do for ((i=1;i<=num_rows;i++)) do matrix[$...
-1
votes
1answer
112 views

How to write the bash script dynamic to print row and columns data and update the same data in the same file? [closed]

abc_hosts,pwd_host_id,pwd_host_id,hostname,ddd_status,dddd_status, start_hosts,,,,,,,,,,,,,,,,,,, ,1,o1,fhffhfh,1,1,fff,fdfd,172.33.33.33,172.30.30.12,172.30.30.11,oreere.dff,43,443343,1111,43435,...
1
vote
1answer
65 views

reading array and summation of elements

! /bin/bash I omitted here though I have used it. I used bash shell only. first integer is the no of variables in the array. yes I did get syntax error. I want to know the problem with my code. need ...
0
votes
2answers
68 views

Write ls to array (split by newline)

I want my directory listing output in an array. readarray x < <( ls -la ) printf "%s" ${x[@]} So I wrote this, which works but it splits by space and not by newline. I can't find a "newline" ...
1
vote
1answer
129 views

compare array in bash

Question: what does this line do? Can someone please explain? if [ $((${array[$i]}+1)) -ne ${array[$(($i + 1))]} ] ;then foo; fi
0
votes
1answer
37 views

Subtraction with Values in an Array

I'm using an array to try to subtraction. However, when my script just gives me the total of my array with a negative sign in front of it. Any suggestions? elif [ "$OP" = "Subtraction" ]; then ...
2
votes
1answer
81 views

Issue with array length in bash script

I am writing a script that stores some of the command line arguments as an array, and uses the array later, but I'm having an issues getting the correct length of the array in the script. In the ...
1
vote
0answers
38 views

removing spare from array using hpacucli

Whilst configuring a new array I have somehow accidentally added the same disk to 2 arrays: => ctrl all show config Smart Array P400 in Slot 1 (sn: PAFGK0P9SX036K) array A (SAS,...
0
votes
2answers
59 views

Define a set of values for a variable in shell script

I want to define a set of values for a single variable. E.g. singleDigit={0,1,2,3,4,5,6,7,8,9} If the user gives 10 it should exit with an error. How can this be achieved without using a loop, but ...
3
votes
1answer
58 views

Ordered by insertion Map in bash

Is there an ordered (by insertion) map in bash? I know there's an associative array data structure in bash, but when iterating over it, the order of the elements is not by insertion. Example below. ...
5
votes
2answers
157 views

Array Expansion

I am having unexpected results in expanding an array. I am hoping someone can shed some light on why I am seeing what I am seeing. I am trying to populate an array using fdisk -l to fill it and only ...
5
votes
4answers
102 views

Is there an easy way to do the equivalent of `sed …` replacing the same line with multiple values?

I have a file where I want to replace some variables with data from a shell script. -A INPUT -i lo -s @LOCAL_IP@ -j ACCEPT Here I want to replace @LOCAL_IP@ with an IP address, I use the following: ...
0
votes
1answer
43 views

parse snmpwalk output to array

Im trying to get network interfaces by doing a snmpwalk, but cannot separate in array, the variable stores all in element 0 ifname=(\$(snmpwalk -Oqv -v2c -c comm xxx.xxx.xxx.xxx 1.3.6.1.2.1.2.2.1.2))...
2
votes
2answers
103 views

Reading a file with IFS loop works only when no arrays are used

Using the following code, I'm trying to read a file into an array: GROUPS=() while IFS=: read -r g1 g2 g3 g4 do GROUPS+=("$g3") echo "$g3" done < /etc/group This doesn't work, it doesn'...
2
votes
1answer
65 views

GNU Parallel: How can I reference array elements?

This is my case scenario: luis@Balanceador:~$ echo ${array[@]} a b luis@Balanceador:~$ echo ${array[1]} a luis@Balanceador:~$ echo ${array[2]} b luis@Balanceador:~$ parallel echo ${array[]} ::: 1 2 -...
1
vote
0answers
32 views

Returning an array from a ksh93 function

I would like to return an array from a function in ksh93. At this point, using the following method, the contents of the array are passed as a single element even though, in the fonction, the array ...
0
votes
0answers
44 views

How to resolve a variable's value inside an array in bash

I have a few files whose names I have assigned into variables. (There may be n number of files). Those variables are passed into an array. Now I want to print the names of the original files using ...
0
votes
3answers
99 views

Bash array values like variables inside loop

Im trying double loop using array values like array names for loop array1="name1 name2" name1="one two" name2="red blue" for name in $array1 do for value in $name do echo "$name - $value" ...
2
votes
2answers
42 views

Build a process substitution list for tee

I have a script like this which I use to broadcast commands to several instaces of the postgresql database CLI connected to several different servers. I'm using a hard-coded set of process-...
0
votes
2answers
36 views

How can I assign the last element of an array to a another array?

Let say I have an array $Info whose elements are ; ! total energy = -1090.13343774 Ry ! total energy = -1090.20757070 Ry ! total energy = -1090....
-4
votes
2answers
102 views

What is wrong in this code? [closed]

The code is ; cm=$1 nm=$2 case $cm in "out") declare -a en declare -a inf ec=$(grep -n "! " hw1_out_si_wire.txt) IFS=$'\n' en=($ec) lst=$((${#en[@]} -1)) IFS=' ' inf=($en[$lst]) echo " Energy: ${inf[...
0
votes
1answer
28 views

Why does the output look like different?

After executing this script, sometimes the output looks like this: 1912:! total e ergy = -1090.13343774 Ry 2310:! total e ergy = -1090.20757070 Ry 2709:! total e ...
1
vote
1answer
82 views

Array indexing using “sed”

I am working on one shell script which search directory modified in last 24 hours and then compress them using tar. Folder Search : find /path to log directory/ -maxdepth 1 -type d -mtime +0 ...
-1
votes
2answers
174 views

How to sum many numbers inside 2D array using awk

I need to sum numbers located in a file like this one: column1 column2 column3 row1 a(1,1) a(1,2) a(1,3) row2 a(2,1) a(2,2) a(2,3) row3 a(3,1) a(3,2) a(3,3) row4 a(4,1) ...
2
votes
1answer
79 views

How to sum numbers inside many 2D arrays

I need to sum numbers located in a file like this one: column1 column2 column3 row1 a(1,1) a(1,2) a(1,3) row2 a(2,1) a(2,2) a(2,3) row3 a(3,1) a(3,2) a(3,3) row4 a(4,1) a(4,2) ...
3
votes
2answers
42 views

Looking for a convenient way to create a “constant array”

In zsh, is there a convenient way to create an array of n copies of the same integer? Context: In a shell script, I need to create an array, tile_lengths, consisting of two longish constant blocks. ...
0
votes
0answers
41 views

Array value won't get printed out

I have the below bash script, but rather that I get the command executed stored in cmd[1] it prints [1]: command not found. I executed the command with the following way: $ qsub -J 1-33 sicer-pbs.sh ...
2
votes
4answers
96 views

String Manipulation Shell Script [duplicate]

I am working on a UPS Monitoring project using NUT Server. My objective is to make a shell script which sends one command and in response receives the status and other parameters from the UPS. for ...
1
vote
1answer
61 views

bash script read array outside loop

This is my first attempt to write a bash script and I'm unable to read array outside for loop. What I'm trying to do is.. store name of all files from /MyDir in an array. Check if there is process ...
2
votes
2answers
68 views

Split words from `read` and store to array?

How can I take input from read, split the words up by spaces, and then put those words into an array? What I want is: $ read sentence this is a sentence $ echo $sentence[1] this $ echo $sentence[2] ...
2
votes
2answers
80 views

find duplicate in first, second columns and sum numbers in third column

I have this input: Fred apples 20 Susy oranges 5 Mark watermellons 12 Robert pears 4 Robert oranges 17 Terry oranges 9 Lisa peaches 7 Susy oranges 12 Mark grapes 39 Anne mangoes 7 Greg pineapples 3 ...
0
votes
1answer
62 views

Match words in array line by line to a seperate file

Here is a sample of my input data: $9.99,Titan the Power,www.example.com,565654 $15.99,Conan The Barbarian,www.sure.com,565438 $1.99,Julia Cesar,www.bfg.com,69722 I have written this code so ...
3
votes
1answer
34 views

why this pattern replacement is not working on array?

for a variable z z="I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX" echo "${z// /,}" output is I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII,XIII,XIV,XV,XVI,XVII,XVIII,XIX,XXOK. ...
0
votes
1answer
31 views

how to get the size of an indirect array in bash?

Without using eval. this wont work: astr=(a b c) str="#astr[@]" echo "${!str}"
0
votes
2answers
44 views

When does an array variable represent the entire array, and when the element indexed by `0`?

Bash manual says: Referencing an array variable without a subscript is equivalent to referencing with a subscript of 0. In Bash or POSIX shell, is there some general rule for when an array ...
1
vote
0answers
25 views

Access to bash arrays in gnuplot [duplicate]

In a bash script I have several arrays which I need to access in a gnuplot code: #!/bin/bash ... # fill array a[*] and b[*] ... gnuplot <<EOF do for [j=0:10] { # access ${a[j]} and ${b[j]} } ...
1
vote
3answers
45 views

Find position of matched word in a line in bash (not position of character)

I have a line like Xckt VDD VSS sig[1] sig[2] sig[3] sig[4] sig[5] sig[6] CKT and I want to find the position of sig[4] in the line. In this case it should return 7. I wanted some simple script/ ...
3
votes
3answers
185 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
3
votes
2answers
87 views

use printf to format output of an array

I have an array that contains details about each NIC. Each array index consists of three space-separated values. I would like to have a nice table as output. Is there a way to assign formatting ...
0
votes
0answers
13 views

Declaring multiple arrays from contents in multiple directories, then iterating over those arrays and their contents [duplicate]

In a bash script, I'm trying to declare 15 separate arrays with the contents of a folder for 15 separate folders (IE; array1 = contents of folder1, array2 = contents of folder 2, ..., array15 = ...
2
votes
1answer
75 views

POSIX Awk sort array

I would like to sort an array with POSIX Awk, however I have discovered that: asort() asorti() PROCINFO["sorted_in"] are all GNU extensions. Can this be done with without GNU Awk?