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

learn more… | top users | synonyms

1
vote
1answer
84 views

awk array using number as value did not work

I have a reference file: Refrence File Dpse\GA30012 FBgn0000447 chr2 26607738 26607962 -1 Dpse\GA19764 FBgn0085819 chrX 28571020 28571736 -1 Dpse\ttk FBgn0000100 chr2 ...
0
votes
2answers
41 views

How can I store each seperate entire line in a text file into an array?

I have a file called "threewords". It contains the information: \#gray speedy bee gr-A | sp-E-d-E | b-E \#gray greedy pea gr-A | gr-E-d-E | p-E When I run the command: cat threewords | grep ^# ...
0
votes
2answers
45 views

for loop not working for multiple lines

I have a array like this "Apple Banana Clementine Date" I have to print like this: 1. Apple 2. Banana 3. Clementine 4. Date Script file: for i in "${fruits[@]}"; do echo "$lineno. $i " ...
0
votes
0answers
38 views

awk - how does the for loop work when counting words? [duplicate]

I have got the following awk script from here that counts the frequency of the words in a file-: # Print list of word frequencies { for (i = 1; i <= NF; i++) freq[$i]++ } END { ...
2
votes
1answer
48 views

Bash Array Comparision

Within a bash script, I am building two dynamic arrays. And I want to construct another array with difference of two. Example: array1=("aa-1234|safsf|sfsfs" "aa-2345|sfsfs|n0sfm" ...
3
votes
3answers
144 views

Split in awk not not printing array values

I have a string tstArr2 which has the following content '3 5 8' Now in awk I want to parse a flat file test my array which array is better array INDIA USA SA NZ AUS ARG GER BRA US AUS INDIA ENG ...
1
vote
0answers
38 views

How to force bash to start at index 0 with select output?

Well, even some less-experienced bash users would know meanwhile about the fact that bash arrays would always start with index 0. However, select will always do its own thing, as the following example ...
1
vote
2answers
37 views

Randomize arguments ( that hold color codes) from an array

I have the array (shown below) with arguments that hold color codes. The intended purpose of my script is to randomize those arguments when the user inputs "scriptname randoms Text" so that every time ...
1
vote
5answers
108 views

How to create an array of unique elements from a string/array in bash?

If I have a string "1 2 3 2 1" - or an array [1,2,3,2,1] - how can I select the unique values, i.e. "1 2 3 2 1" produces "1 2 3" or [1,2,3,2,1] produces [1,2,3] Similar to uniq but uniq seems ...
2
votes
2answers
48 views

How to select unique array values?

I have an array and I want to get the unique 2nd members bash doesn't really have 2-dimensional array so I've defined it this way, using :: as the separator of the two elements: ruby_versions=( ...
5
votes
1answer
121 views

Provide two arguments to one option using getopts

In below code when I give option r then getopts requires one arguments: while getopts ":hr::l:" opt; do case $opt in r ) echo "Run Numbers - argument = $OPTARG " ;; l ) echo ...
0
votes
1answer
105 views

Trying to access environment variable (array) declared in ~/.profile from shell script

I'm currently fighting with this problem. I've already read some older posts here on SE, and got the conclusion that the only sane way to put a variable (even an array) is ~/.profile. So OK, array ...
1
vote
4answers
153 views

How to split text file into records by first non-blank charecter using awk and print only records containing string

I have a text file with information separated in blocks. I would like to separate these blocks into records so that I can handle them separately. This is my text file (file.txt): Alarm Stats: ...
1
vote
1answer
59 views

Zsh script how to concatanate array elements with string

I have written a zsh script to automize an analysis in high energy physics and now I would like to use an element of the one of the defined array some string and another element of some another array ...
0
votes
1answer
36 views

Cannot access elements of an array in zsh

I am trying to write a script in zsh and I need to make use of arrays in order to achieve my aim in an elegant way. After reading some information over the Net, I tried to implement and access the ...
0
votes
3answers
282 views

Bad substitution error in zsh shell

Hi in my previous question I got clarity on how to use associative arrays in zsh shell. But whenever I trigger the following command in my script for KEY in ${!array[@]} to iterate amongst the keys ...
0
votes
1answer
106 views

typeset -A is giving error in script

I was using associative arrays in my script, hence I used to declare them by the typeset -A <array_name> command, and it worked fine in the bash prompt But when I use it in my script, I get ...
2
votes
2answers
79 views

Memory allocation for sparse array in awk

I have searched but didnt reach to any conclusion that when i defined an sparse array does it reserve all the contiguous memory upto maximum index or it allocate the memory at that particular index ...
1
vote
1answer
74 views

How do I add an associative array to a variable from an external ini file?

I'm modifying a simple script to add function and learn more about how to write bash scripts. Currently, the script creates associative arrays using a function: declare -A site theme add_site() { ...
0
votes
3answers
198 views

store the command output in an array and print one by one

This is my command: cat httpd.conf | grep ^LogFormat | awk -F\" '{print $(NF)}' Output of this: commonsess common or can be any number of values, I need to store these values in an array and ...
0
votes
1answer
3k views

mdadm raid doesn't mount

I have a raid array defined in /etc/mdadm.conf like this: ARRAY /dev/md0 devices=/dev/sdb6,/dev/sdc6 ARRAY /dev/md1 devices=/dev/sdb7,/dev/sdc7 but when I try to mount them, I get this: # mount ...
6
votes
1answer
490 views

Delete an array in awk

In awk, I can clear an array with a loop, making it an empty array, which is equivalent to deleting it. for (key in array) delete array[key]; Is there a simpler way? Can I completely delete an ...
1
vote
1answer
118 views

How can I use global variable arrays in aliases or functions

I am attempting to simplify repetitive work procedures. In doing so, I am trying to write a .bashrc script which will set global path variables that aliases can refer to. Disclaimer: I'm new to linux ...
4
votes
4answers
164 views

Indirection on a Bash array

Is there a possibility to write the following script without the loop? IPv4_first=1.1.1.1 IPv4_second=2.2.2.2 IPv4_third=3.3.3.3 IPv4_all=() for var in ${!IPv4_@} do IPv4_all+=(${!var}) done ...
1
vote
2answers
372 views

sh + how to use array in sh script in order to print all values in array

I want to use arrays in my sh script. My target is to create an array with the values a b c and print all values in the array. I succeeded to print each array, but I failed to print all values in ...
2
votes
4answers
805 views

How to initialize an array using awk and bash?

I am trying to store values of the first line of a text file into an array. Here is what I have so far: arr_values=() awk ' NR==1 { for (i=0; i<=NF; i++) ...
8
votes
2answers
3k views

Array in unix Bourne Shell

I am trying to implement array in Bourne shell (/bin/sh). I found that way to initialize array elements is: arr=(1 2 3) But it is encountering an error: syntax error at line 8: `arr=' unexpected ...
1
vote
1answer
47 views

Bash array declared in a function is not available outside the function

on bash (v4.3.11) terminal type this: function FUNCtst() { declare -A astr; astr=([a]="1k" [b]="2k" ); declare -p astr; };FUNCtst;declare -p astr (same thing below, just to be easier to read here) ...
4
votes
1answer
101 views

What is the difference between @ and * when referencing bash array values?

This Bash guide says: If the index number is @ or *, all members of an array are referenced. When I do this: LIST=(1 2 3) for i in "${LIST[@]}"; do echo "example.$i " done Gives: example.1 ...
0
votes
1answer
738 views

How to do array addition multiplication program in a shell script? [closed]

Write a program arr_calc to perform array addition and array multiplication, The program takes 4 arguments: Argument 1: The file name of the input array A Argument 2: The file name of the input array ...
0
votes
2answers
390 views

Using regex in for loop

I'm looking to loop through a directory of files and match them with regex, then subsitute the appropriate character: #somefile.txt %somefile.txt >somefile.txt # arr=(\% \> \#) ;for f in *; do ...
1
vote
1answer
53 views

Error when constructing an associative array

I am trying to construct an associative array in bash #!/bin/bash declare -A hero_escore hero_escore=( "Invoker_Anti-Mage : -44" "Tinker_Nyx Assassin : 32" "Troll Warlord_Drow Ranger : ...
2
votes
2answers
535 views

Creating an array with IFS set to a different value

I am trying to construct an array and write to a file in this format, i.e. the file's content should be something like this hero_pairscore=( askdjfh sdf,sdlkfj lksf,dfgdf,dsflkgj,asdlkf ....) Where ...
0
votes
2answers
113 views

Reversing 1-D array

I'm trying to reverse a 1-D array which contains a list of files. I followed http://stackoverflow.com/questions/13360091/how-to-reverse-array-in-bash-onliner-for-loop to be the code. But this is not ...
1
vote
2answers
680 views

get arguments passed and put it in an array

is there a way to make the arguments passed become the element of an array? I want to access those arguments individually through array. like this: ./script.ksh arg1 arg2 arg3 then it will become ...
2
votes
3answers
228 views

List all word pairs that appear in a line together in a file

How can I use awk to run through a file written as: Sarah,Masha,Helen Connor,Jessica,Jennifer,Candace Betty,Sarah,Helen John,Harold,Frank,Daisy and put out all pairs that appeared in a line ...
2
votes
1answer
332 views

What is an array in awk?

I'm very new to unix and am trying to learn basic awk scripting - during which I keep coming across the word "array", and "associative arrays". I have no clue as to what this is, and don't tell me to ...
1
vote
1answer
127 views

Is there a simple way to get array of all arguments that do not begin with a hyphen?

zsh includes a powerful utility for parsing command-line options zparseopts, but for quick shell scripts and shell functions, but is there an easy way to extract the array of all command-line ...
5
votes
2answers
4k views

Associative Arrays in Shell Scripts

I saw a trick for implementing associative arrays in a shell script. For example print array["apples"] could be scripted as echo \$array$key where key=apples. However, there was no mention of how to ...
1
vote
2answers
54 views

Is this an array?

I'm currently looking at an existing script that have something like this: variable='val1 val2 val3 val4' Is this another way of setting an array? If not, what is it?
1
vote
1answer
118 views

Bash Array does not store correctly

I have a problem with my bash array I was trying to read the file however the array allocated it in array[1] instead of 0 #!/bin/bash index=0 INPUT=BookDB.txt OLDIFS=$IFS IFS=: i=0 book=() [ ! -f ...
1
vote
1answer
132 views

Count number of elements in an array

I would like to ask if there is a way to count the number of elements in an array in ksh.
3
votes
2answers
173 views

How do you preserve a space in a literal expression in an array value in bash and how to trim down results from a sort command?

In the context of searching for expressions in log files, I was wondering generally if there was a way to quantify and qualify the contents of the logs in /var/log in some way. In particular, does the ...
1
vote
1answer
177 views

Attempt to fake a 2D multidimentional array in bash by storing the array name as string

I am trying to create a structure that will allow me to group data inside an array in bash Here is what I have tried: indexes=() first_element=( value='one' another_value='two' ...
2
votes
2answers
204 views

Bash scripting: Associated Array only recognizes one value when several given

This lines of a Bash (4.0) Script klang=([string_0]='element_0' [string_1]='element_1' [string_2]='element_2') echo "${klang[*]}" # should output the all set elements echo "${#klang[*]}" # ...
1
vote
1answer
420 views

Problem with sed on a array containing strings containing spaces

I have a array looking like this: array=("(1 2 3) (123)" "2 31 (231)" "4 5 1 (451)" "(te)xt (1234)") This array is a example. It does not look like this but its structure is the same (the strings ...
6
votes
4answers
2k views

Intersection of two arrays in BASH

I have two arrays like this: A=(vol-175a3b54 vol-382c477b vol-8c027acf vol-93d6fed0 vol-71600106 vol-79f7970e vol-e3d6a894 vol-d9d6a8ae vol-8dbbc2fa vol-98c2bbef vol-ae7ed9e3 vol-5540e618 ...
0
votes
1answer
146 views

I need Control loop help -

this is what I figured out in sorting an Array that has already had it's elements declared type int #!/bin/bash #sorting an "predeclared" array typeset -i store BigNum let store=0 BigNum=0 ...
0
votes
1answer
2k views

How to reassign new values to array elements?

I'm trying to figure out like three or four things at the same time.The most I need help with is how to get the greatest number in all the files that I have created on a prior run of my script, that ...
-1
votes
1answer
109 views

find not working right

if [[ "$1" == "" ]] then leftarray=($(find . -type l -printf "%p\n" 2>/dev/null)) rightarray=($(find . -type l -printf "%l\n" 2>/dev/null)) for var in "${rightarray[@]}" do ...