It's by sheer coincidence that you get anything from that code snippet. The field separator should be set to comma, but due to an incorrect syntax it isn't. The a array holds one single element only, indexed by the empty string, and is overwritten repeatedly until the first file's last line is encountered. As $13 doesn't exist in file 2 and thus is empty, that only element of a is printed. You seem to want to ignore the commas inside the double quotes, so the entire quoted string will be considered field 1? If so, they need to be replaced upfront, and then converted back after the operations.
Would this come close to what you need:
Hi,
I have two input files as
File1 :
ABC:client1:project1
XYZ:client2-aa:project2
DEF:client4:proj
File2 :
client1:W-170:xx
client2-aa:WT-04:yy
client4:L-005A:zz
Also, array of valid values can be hardcoded like
Output :
ABC:W:project1
XYZ:WT:project2 (1 Reply)
Hi! Is there a way to append column and row header to a file in awk script.
For example if I have
Jane F 39 manager
Carlos M 40 system administrator
Sam F 20 programmer
and I want it to be
# name gend age occup
1 Jane F 39 manager
2 Carlos M ... (4 Replies)
Is there any way I can achieve this?
Considering test1 :
a 1 2 3 4
b 2 3 4 5
c 12 1232 14 1
d 10 13 4 5
e 1 5 6 9 1
And test to be some string :
qw
twe
tew
we
qw
I want something like this :
a 1 2 qw 4
b 2 3 twe 5 (5 Replies)
I have a file like:
I would like to find lines lines with duplicate values in column 1, and retain only one based on two conditions: 1) keep line with highest value in column 3, 2) if column 3 values are equal, retain the line with the highest value in column 4.
Desired output:
I was able to... (3 Replies)
Hi have a large spreadsheet which has 4 columns
APM00111803814 server_2 96085 Corp IT Desktop and Apps
APM00111803814 server_2 96085 Corp IT Desktop and Apps
APM00111803814 server_2 96034 Storage Mgmt Team
APM00111803814 server_2 96152 GWP... (6 Replies)
input
"A","B","C,D","E","F"
"S","T","U,V","W","X"
"AA","BB","CC,DD","EEEE","FFF"
required output:
"A","B","C,D","C,D","F"
"S", T","U,V","U,V","X"
"AA","BB","CC,DD","CC,DD","FFF"
tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Good evening
I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this.
I have file called file1 and file2.
I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Hi Experts,
Please bear with me, i need help
I am learning AWk and stuck up in one issue.
First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique.
Second point : For... (1 Reply)
Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2
Scenario 1
i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
hi
I have 2 file with more than 10 columns for both
1st file
apple,0,0,0......
orange,1,2,3.....
mango,2,4,5.....
2nd file
apple,2,3,4,5,6,7...
orange,2,3,4,5,6,8...
watermerlon,2,3,4,5,6,abc...
mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies
LEARN ABOUT REDHAT
array
array(n) Tcl Built-In Commands array(n)
__________________________________________________________________________________________________________________________________________________NAME
array - Manipulate array variables
SYNOPSIS
array option arrayName ?arg arg ...?
_________________________________________________________________DESCRIPTION
This command performs one of several operations on the variable given by arrayName. Unless otherwise specified for individual commands
below, arrayName must be the name of an existing array variable. The option argument determines what action is carried out by the command.
The legal options (which may be abbreviated) are:
array anymore arrayName searchId
Returns 1 if there are any more elements left to be processed in an array search, 0 if all elements have already been returned.
SearchId indicates which search on arrayName to check, and must have been the return value from a previous invocation of array
startsearch. This option is particularly useful if an array has an element with an empty name, since the return value from array
nextelement won't indicate whether the search has been completed.
array donesearch arrayName searchId
This command terminates an array search and destroys all the state associated with that search. SearchId indicates which search on
arrayName to destroy, and must have been the return value from a previous invocation of array startsearch. Returns an empty string.
array exists arrayName
Returns 1 if arrayName is an array variable, 0 if there is no variable by that name or if it is a scalar variable.
array get arrayName ?pattern?
Returns a list containing pairs of elements. The first element in each pair is the name of an element in arrayName and the second
element of each pair is the value of the array element. The order of the pairs is undefined. If pattern is not specified, then all
of the elements of the array are included in the result. If pattern is specified, then only those elements whose names match pat-
tern (using the matching rules of string match) are included. If arrayName isn't the name of an array variable, or if the array
contains no elements, then an empty list is returned.
array names arrayName ?pattern?
Returns a list containing the names of all of the elements in the array that match pattern (using the matching rules of string
match). If pattern is omitted then the command returns all of the element names in the array. If there are no (matching) elements
in the array, or if arrayName isn't the name of an array variable, then an empty string is returned.
array nextelement arrayName searchId
Returns the name of the next element in arrayName, or an empty string if all elements of arrayName have already been returned in
this search. The searchId argument identifies the search, and must have been the return value of an array startsearch command.
Warning: if elements are added to or deleted from the array, then all searches are automatically terminated just as if array done-
search had been invoked; this will cause array nextelement operations to fail for those searches.
array set arrayName list
Sets the values of one or more elements in arrayName. list must have a form like that returned by array get, consisting of an even
number of elements. Each odd-numbered element in list is treated as an element name within arrayName, and the following element in
list is used as a new value for that array element. If the variable arrayName does not already exist and list is empty, arrayName
is created with an empty array value.
array size arrayName
Returns a decimal string giving the number of elements in the array. If arrayName isn't the name of an array then 0 is returned.
array startsearch arrayName
This command initializes an element-by-element search through the array given by arrayName, such that invocations of the array nex-
telement command will return the names of the individual elements in the array. When the search has been completed, the array done-
search command should be invoked. The return value is a search identifier that must be used in array nextelement and array done-
search commands; it allows multiple searches to be underway simultaneously for the same array. |
array unset arrayName ?pattern? |
Unsets all of the elements in the array that match pattern (using the matching rules of string match). If arrayName isn't the name |
of an array variable or there are no matching elements in the array, then an empty string is returned. If pattern is omitted and is |
it an array variable, then the command unsets the entire array.
KEYWORDS
array, element names, search
Tcl 8.3 array(n)