All Questions
51 questions
3votes
1answer
827views
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 ...
2votes
5answers
617views
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. ...
1vote
2answers
376views
awk matching fields in 2 separate files using command containing {BEGIN FS = "|"} returns output of blank lines
Two files: data1 Name |formula |no. |dose|days|cost |msg|em|notes Fname-Lname|BXXXT+GG |8262|4 |14 |57.78 | | |sq Fname-Lname|SJXXT+GG |8263|4¾ |...
-1votes
1answer
271views
write bash code loop a file line by line that have values, first word as a row and create csv [closed]
i have this sample data dn; uid=456456456,cn=users,dc=efsfb,dc=org,dc=co; objectclass; top; objectclass; person; objectclass; organizationalPerson; objectclass; inetOrgPerson; uid; 456456456; ...
1vote
1answer
112views
AWK: Add missing lines in csv file and set specific column to "0"
(Note: this question is heavily shortened because the detailed question was blocked with "This looks like spam.") I'm having a hard time adding missing lines to a series of data in a ...
2votes
1answer
46views
Loop through file with unique identifer and compute cumulative sum
I have a large text file, as shown below, where column1-colum3 define a region and fourth column is unique identifier. The column 6 is assigned value of the region. chr6 26204834 26204839 ...
1vote
2answers
3kviews
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"...
1vote
4answers
350views
Array in AWK need clarification on code
I've been tasked to create a list whereby one of the codes in the original data is to be replaced by a new code read in from a reference list. In this case there is just one change, but there could ...
0votes
2answers
741views
Filtering rows of a dataframe with AWK to only show entries in a given field with X instances
I have a large dataframe, in which one of the fields("ID") correspond to a unique identifier. However, there are multiple instances of that value, depending on the binary combination of additional ...
0votes
1answer
995views
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 ...
1vote
3answers
578views
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 ...
2votes
2answers
345views
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 ...
0votes
1answer
216views
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 "," ...
8votes
1answer
3kviews
Referencing array elements by strings, and initialising arrays in awk
#!/usr/bin/env bash awk ' BEGIN { arr[A]=1; arr[B]=1; arr[C]=1; arr[E]=1; arr[J]=8; arr[Q]=10; print arr[J] }' the above command outputs the latest set value for arr['...
1vote
7answers
379views
Create PHP array from letters
I would like to create a PHP array from the Serbian alphabet. Out of а б в г д ђ е ж з и ј к л љ м н њ о п р с т ћ у ф х ц ч џ ш a b c č ć d dž đ e f g h i j k l lj m n nj o p r s š t u v z ž should ...