Questions tagged [array]

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

Filter by
Sorted by
Tagged with
0
votes
3answers
35 views

using sed with variables defined in 2 arrays

I have followed the very many posts on this site regarding the subject but I am still clearly doing something wrong... My goal is to define values in two different arrays, then use sed to search a ...
0
votes
1answer
25 views

I would like to analyze a TXT file, but the data is a 1 column array, and it needs to be a in a multi-column array

Is there a way for me to manipulate the data (i.e.; change some feature of, so that it looks like it should, a multi-column array) without having to manually go through it? There are thousands of rows ...
0
votes
1answer
24 views

Extract CSV column containing blank space to Bash array

I would like to export a CSV bookmarks file as Physics,physics.stackexchange.com Stack Overflow,stackoverflow.com Unix & Linux,unix.stackexchange.com into two Bash arrays. Each array would ...
3
votes
2answers
264 views

Assign $@ to another variable in a shell function

I'm making an intelligent alias gc that can differentiate git commit/checkout. If gc is called without any arguments or with the -a, -m arguments, then git commit is run. Otherwise, git checkout is ...
0
votes
0answers
20 views

why does matching a value in an array work on the CLI but not in a script?

So I have an array: the contents of $tmp would be like "00-value" "00-derp" in the script the array is input into a variable and then later called: inst_array=$(cat $tmp) for x in "${inst_array[@...
0
votes
1answer
49 views

Pass Bash associative arrays as argument to jq filter

I am working with some location data and am querying an API with U.S. postal codes and returns a result like: { "resultStatus":"SUCCESS", "zip5":"30301", "defaultCity":"ATLANTA", "...
0
votes
2answers
71 views

Is there a way to modify $@ array in a POSIX shell script

I may know how to use readlink to get normal files from SymLinks. I had this very basic idea to replace any SymLink in $@ passed to my function as follows: for file in "$@"; do [ -L "$file" ] &...
-1
votes
0answers
28 views

Python, getting max value of an array with a simple loop [migrated]

I am writing a simple loop to get the max value inside an array. I know there is the function arr.max() but I'm just curious why the following code does not work. import numpy as np arr1 = np.arange(...
1
vote
1answer
63 views

Copy bash array to a variable which name is hold by another variable

There are many similar questions, but I didn't understand any answer as solution of the following problem: I want to create a bash function which holds two arguments, first is a variable name and ...
-1
votes
2answers
33 views

Changing permission on multiple files within bash

I am trying to write a script to change the permissions of a number of other scripts, in multiple locations, to be executable. I've searched all over and can't seem to get the syntax correct. It is ...
0
votes
0answers
45 views

bash: problem with looping through array of directory paths

Array arr1 contains two directory paths extracted with find command: echo "${arr1[@]}" /archive/logs/2020/02 /archive/raw/2020/02 I am testing if I can loop through the array arr1 with this code: ...
0
votes
1answer
28 views

User input to search bash array

folks-- I'm getting kinda stuck, here. I have a small script that will be incorporated into a larger script. This small piece is supposed to take a user input, and compare it to a list of stored ...
2
votes
2answers
124 views

zsh: for loop over newline-delimited entries

I have a variable: ❯ echo $numholds 409503 409929 409930 409932 409934 409936 409941 409942 409944 409946 I want to do a for loop of it, but the newline-delimitation doesn't work: ❯ for num in ...
1
vote
1answer
44 views

How do I filter the contents of a json array, but keep the parent with jq?

I have some JSON that looks like this: { "Vpcs": [ { "VpcId": "vpc-1", "OwnerId": "abc" }, { "VpcId": "vpc-2", "OwnerId": "def" } ] } I just want the ...
0
votes
0answers
15 views

Attempting to write PHP array to file in Linux PHP interactive shell produces Uncaught Error and empty file

After executing the following commands: [root@server test]# php -v PHP 7.2.25 (cli) (built: Dec 17 2019 22:57:09) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-...
1
vote
2answers
64 views

bash array not be properly processed when mapfile is used to read in values

this one has me baffled. Here are 2 versions of loading a bash array, one works, the other does not. If I explicitly initialize the array within the script, it works fine: zz=( 1 26 32 54 71 13 30 ...
2
votes
1answer
119 views

How to extract data more Efficient in an array?

I have a directory with some text files that have data like below; I read them via a loop and put each line in an array! I don't know the correct way and if you know any better way, let me know. ...
0
votes
1answer
105 views

Read csv from shell script and print the column header based on closest match to user input

I Have a csv file. It has multiple columns. I want to develop a shell script which prompts the use for a numerical value, find the closest match in the csv and print the header of the column. For ...
0
votes
3answers
135 views

Mathematical operations - Bash script

I am trying to write a script(script1.sh) that gives the sum of each digits in the first number, raised to the power of second number. So ./script1.sh 12345 2 should output 55 (because 1+4+9+16+...
0
votes
1answer
36 views

Work around spaced-filenames in array construction

I'm using the command files=( $(ls "/path/wanted") ) to store all filenames from a directory in an array. However filenames that contain space character result in multiple array entries. To figure ...
0
votes
4answers
381 views

Convert JSON Array to Bash

I'm using JQ to fetch some JSON from a quiz database and I want to parse the results. I'm trying to save a resulting array in Bash as shown below but the format is that used in JavaScript/Python with ...
1
vote
2answers
76 views

Sum occurrences of string for each row of a matrix using awk

I have a very long data frame (~11 million x 130) for which is sparsely filled with percentages (0.00 - 100.00, float). The entries that are missing are labeled "NA", like so: cat1 NA NA ...
0
votes
2answers
57 views

Error while using array in AIX : syntax error error at line 81 : '(' unexpected

I am trying to execute one .sh script in AIX environment, but it's giving an error at below line tableList = ( Value1 Value2 Value3 ) I have tried executing the script like below: sh file1.ksh I ...
0
votes
1answer
37 views

More efficient zsh string parsing / array handling

Is there any more efficient way to do the following in zsh? I imagine that there might be ways to get rid of the intermediate array parameters a and/or b. The script gets some output from a command. ...
0
votes
1answer
26 views

In zsh, what is the difference between (${(@s.\n.)s}) & (${(@s/\n/)s})

In zsh, what is the difference between (${(@s.\n.)s}) (dots) & (${(@s/\n/)s}) (slashes), e.g., in: s=a\\nb\\nc\\nd a=(${(@s.\n.)s}) b=(${(@s/\n/)s})
2
votes
2answers
224 views

Iterate through array of strings applying a Regex to each element in Korn Shell

I have an array of strings called names containing names with some subsequent garbage data. Like this Jill Shortz, City Contractor, America Bill Torts, Family Doctor, Canada Will Courtz, Folk DJ, ...
0
votes
1answer
104 views

mdadm RAID1 array - is it required to partition?

I've been using an mdadm RAID1 array with 2 2TB disks for a few years without issues. Recently I needed to upgrade it to 4TB so I bought 2 new disks of 4TB and plan to replace one, wait for the ...
0
votes
1answer
58 views

Why do these rsync filter args fail in bash when passed in array?

Why does this rsync command work when I give it literally but not when I create it from variables? Here are the variables - first the options I'm passing to rysnc, as an array: $ echo "${options[@]}"...
8
votes
3answers
2k views

Bash to check if directory exist. If not create with an array

I want to write a Bash script, which checks if all directories, stored in an array, exist. If not, the script should create it. Is this a correct way to do it? array1=( /apache /apache/bin /apache/...
1
vote
1answer
47 views

Bash Syntax for Using GREP to Extract Text from File and Store in an Array

I have recently upgraded from bash 4.2.46 to bash version 4.2.50 I had a script with the line: mapfile -t my_array < <(grep ${ID} -w /etc/passwd | cut -d ":" -f 1,4,5) where ID is an ...
1
vote
2answers
69 views

I am having difficulties with back-reference in awk

Recently, I am into security logs and want to make it better way on bash-shell. I found out in awk back-references are only stored by 9. But I need to use 10 back-references. Tried awk '{print ...
-1
votes
1answer
49 views

UNIX AIX using Array to store name and path then get them using for loop separately

I have a script in which i need to create an array with the Path and Name of some files, then i need to pass the Path and Name separately to another script after checking the user's arg matching one ...
0
votes
1answer
56 views

Awk function, syntax error near unexpected 'myArr,'

I am not sure why my simple function causes "Syntax error near unexpected 'myArr,'. I taking an array, lookup key value and a line item section name as arguments. Each row in the array is "," ...
3
votes
2answers
857 views

bash array of arrays

Trying to write some nested loop, and I'm not getting how to write it. Perhaps I'm looking in a wrong direction but what I'm trying to write is: declare -a bar=("alpha" "bravo" "charlie") declare -a ...
1
vote
1answer
30 views

Array only returns one element

i'm trying to generate a script that ftp some files to a server using lftp. when i run these commands in shell: DBNAME=TESTDB ls -t /data*/${DBNAME,,}Backup/$DBNAME.0.db21.DBPART000.`date +%Y%m%d`...
0
votes
2answers
230 views

Bash - sort and uniq on array

This is a similar question to this one I want to do the word count but this time, using an array. For example, I have the following IPs inside a bash array called IPS. IPS=("1.1.1.1" "5.5.5.5" "3.3....
0
votes
0answers
56 views

Bash array length - my code always gives 1 or 0 but should have infinite varaibility

Yes similar questions have been asked, but none of those answers have shown me what I am missing here. I think my problem is in not fully understanding what I am generating with my code... ...
1
vote
0answers
39 views

Performing job array by reading in file paths from a text file

I am trying to perform a job array using script below. #!/bin/bash --login #$ -cwd #$ -t 1-4 module load apps/bioinf module load apps/trimmomatic/0.36/noarch file=`awk "NR==$SGE_TASK_ID" ~/scratch/...
-1
votes
1answer
99 views

I am trying to get a value the i just want the last date and time only [closed]

Trying to get a value date and time not the whole log ${1} - Command Line Arguments in Bash ${i} - Array Item in for Loop grep -ERh "stopped" ems_*/SystemOut*.log | tail -1 Now the value is like ...
6
votes
1answer
1k views

BASH script: How to assign each line of command output to values in an array?

When running a command, I get 10 lines of output. I want to take lines 2-4-6-8-10 and put them into an array. Every time I run my command, the order changes so I need to do this in one go. I had ...
1
vote
0answers
28 views

Set i'th value of kernel module array with command line arguments

Given a kernel module arraymod.c with the following array declaration: static int myintArray[2] = { -1, -1 }; static int arr_argc = 0; module_param_array(myintArray, int, &arr_argc, 0000); ...
0
votes
1answer
113 views

Bash get array length with offset

I'm doing a bash script and I need to get the length of an array starting from an element. Let's say that the array is: array=(1 2 3 4 5) It is possible to print the array with an offset of 2 using:...
1
vote
1answer
460 views

how to combine 2 arrays into one associative array

i need to combine ARRAY1 and ARRAY2 into an associative array like ARRAY. i'm using this code: mapfile -t ARRAY1 < <(/bin/awk '{ print $ 1 }' /output/gen_branch) mapfile -t ARRAY2 < <(...
2
votes
2answers
69 views

bash: Match and replace user input with another array

First of all, sorry for the heading. I'm not sure how to place my ambition in a few words. However, from a coding/scripting standpoint it should be pretty basic. Though, I somehow fail to achieve it :/...
0
votes
3answers
293 views

Find command: name in list

I have a file with a list of names: john paul ringo george ... Then I have a bunch of files with a lot of different names: maria.iso jose.iso pablo.iso john.iso jack.iso jane.iso ... I want to ...
2
votes
3answers
236 views

How to convert file of strings separated by a new line to array

I have a file with data like this: UserName UserName UserName Each piece of data is separated by a new line. I need that data to be converted to an array of strings and stored in a variable. How ...
0
votes
1answer
124 views

tcsh: search entire array for a variable

I am modifying a suite of scripts written in tcsh. Unfortunately, these scripts can't be rewritten because the program they interface with is also written in tcsh. I just want to get out of the way ...
4
votes
4answers
400 views

Just one file echoed from an array of files

I try to copy 2 or more files from one directory to another with cp using an array. I executed: files=( LocalSettings.php robots.txt .htaccess ${domain}.png googlec69e044fede13fdc....
1
vote
2answers
267 views

What's the idiomatic way of returning an array in a zsh function?

I have this function, rpargs () { local i args=() for i in "$@" do test -e "$i" && args+="$(realpath --canonicalize-existing -- "$i")" || args+="$i" done } And I ...
1
vote
2answers
89 views

How can I set default value in parameter substitution as an array of elements?

I'm using zsh, and I have this function: function timer-raw() { # Just think `loop fsayd` is `echo hi` for the purposes of this question. eval "sleep $((($1)*60))" && eval ${(q+@)@[2,-...

1
2 3 4 5
10