All Questions
14 questions
3
votes
1
answer
827
views
Cut or Awk to save lines on array in bash
I have a scenario that I have to put lines of a file .txt inside an array, example of file content;
type of host
|
| first host
| |
| | second host
| | |
| | | same ip ...
2
votes
5
answers
617
views
match value2 in 2 files if value 1 is exact match
I have 2 files containing list. Column 1 is userIds & column 2 is associated values
# cat file1
e3001 75
n5244 30
w1453 500
#cat file2
d1128 30
w1453 515
n5244 30
e3001 55
Things to consider.
...
1
vote
2
answers
3k
views
Write values with embedded commas from arrays into CSV file using BASH
I am trying to write different arrays into a csv file ($file) columns.
Each array has the same number of values.
For example, arr1 and arr2 have 3 values each
arr1=( 23 45 34 )
arr2=( "abc,d"...
25
votes
5
answers
29k
views
how to shift array value in bash
we want to build 6 mount point folders as example
/data/sdb
/data/sdc
/data/sdd
/data/sde
/data/sdf
/data/sdg
so we wrote this simple bash script using array
folder_mount_point_list="sdb sdc sdd sde ...
14
votes
8
answers
18k
views
How to test if array elements are all equal in bash?
The following array represented the numbers of disks on each linux machines
Each single array includes the number of disks on a linux machine.
echo ${ARRAY_DISK_Quantity[*]}
4 4 4 4 2 4 4 4
what is ...
4
votes
4
answers
4k
views
Cannot parse space-separated output of awk
If I understand correctly, the default separator for the output of awk is space.
However, the following script does not behave as I expect. I do not manage to parse the output of awk into an array:
#...
0
votes
3
answers
7k
views
AWK Compare Column 1 from Two Files Print append column to third in output
Looking to compare the first column of two input files that have an identical format. The format looks like the following:
FILE1:
0000abc5abc3 GR096
0000def5ae87 GR001
0000cab5aea3 GR001
...
0
votes
1
answer
2k
views
How to store output of awk to array with empty string on null values? [duplicate]
I have a variable animals.
animals=lion*tiger*elephant**cat***dog
I just want to split by the delimiter * and store it into an array.
Expected:
animals[0]="lion"
animals[1]="tiger"
animals[2]="...
1
vote
1
answer
514
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
2
answers
626
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) ...
1
vote
3
answers
568
views
Put big data of heterogenous byte offset into arrays by AWK
Assume the data consists of byte offset which is not fixed i.e. the distance of two subsequent file headers varies.
The point of this thread is to go through each size of events separately in arrays. ...
2
votes
3
answers
1k
views
access elements in string array - stray @ symbol
I have created an array (3 elements), and each element contains a comma delimited string.
The array was created by reading a file line by line - the file contains fields output from a database.
I have ...
2
votes
4
answers
12k
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++)
'...
4
votes
2
answers
7k
views
How to sum a bash array of numbers (some in scientific notation)?
Since the following command using bc does not work for numbers in scientific notation, I was wondering about an alternative, e.g. using awk?
sum=$( IFS="+"; bc <<< "${arrValues[*]}" )