Skip to content
Advertisement

Tag: arrays

Sorting an array of dates in bash

I want to sort an array of dates. Example format: “2017-11-13_07-55-40” or Year-Month-Date_Hour-Minute-Second Answer Since your dates are already in YYYY-MM-DD-HH-MM-SS format, you can use numeric sort: To store output in another array use:

error while returning a char from a function in C [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 5 years ago. Improve this question hello, I am trying to pass and return a char in C but

How to “grep” in array with dot “.” precisely?

I’m trying to check if the user input $1 exist in an array. And here is my code: What I expect is only “aaa.bbb.ccc” or “ccc.ddd.aaa” can be found. However, in this case, like “aaa” or “ccc” can also pass the validation. Seems like the dot is not treated as part of the string. Should I use regex or other

JSON list (not object) to Bash array?

I’ve got a JSON list (the value of a key-value pair containing a list of items): [ “john”, “boris”, “joe”, “frank” ] How would I convert this to a bash array, so I can iterate over them? Answer Easy Case: Newline-Free Strings The simple approach is to use jq to transform your list into a line-per-item, and read that into

How to store command output into array in Ansible?

Essentially, I want to be able to handle “wildcard filenames” in Linux using ansible. In essence, this means using the ls command with part of a filename followed by an “*” so that it will list ONLY certain files. However, I cannot store the output properly in a variable as there will likely be more than one filename returned. Thus,

move single string up into previous row

I have been trying to solve a problem for hours and haven’t found a solution. I am trying to reformat a text file that has been incorrectly parsed. The file format contains a list of names, starting with the last name first, and has a troublesome sole first name on one of the rows as below: I have tried dumping

Bash Array Key from User Input

So I have a bash script which will scan a directory and run a function on a selected input. It seems that for some reason, the key is not setting from the array properly. What am I missing? All help is much appreciated! EDIT: As a side note, I can run the commands separately and get results. Here is the

Advertisement