File #2:
For File#1, I want to add a column. The content of this column is from File#2.
The procedure is, for each line in File#1,
first, search the line in File#2 satisfies: $1(in File#2) == $3(in File#1), $2(in File#2) == $4(in File#1),
e.g., for line#1 in File#1, find the line in File#2 satisfy $1==H2'' and $2==G ;
then, add $3 of File#2 to the end of the line in File#1, e.g., add 1.34 to the end of line#1 in File#1.
Thank you!
Last edited by rockytodd; 08-14-2009 at 02:38 PM..
To keep the forums high quality for all users, please take the time to format your posts correctly.
Use Code Tags when you post any code or data samples so others can easily read your code.
You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Avoid adding color or different fonts and font size to your posts.
Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
From your example, that script can do what you want:
the first command, we create an empty file3 ;
the first while loop: we read a ${line1} from file1 and we extract the third and fourth fields;
the second while loop, we read ${line2} from file2, we extract the first two fields, then we compare the two strings. If they match, we add ${line1} and the third field from file2 on file3.
Awesome, but I can't understand either ...
From what I can read, a[$1FS$2] seems to be related to file2 (FS is a field separator)
NR and FNR are built-in awk variables
a[] is an array, but why is it refering to file2... mystery ^^ or maybe [$1FS$2] is a character class, I don't understand , still reading the man for more infos
Hi All,
I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record.
For example, let's assume for column D... (9 Replies)
Hi,
My input files is like this
axis1 0 1 10
axis2 0 1 5
axis1 1 2 -4
axis2 2 3 -3
axis1 3 4 5
axis2 3 4 -1
axis1 4 5 -6
axis2 4 5 1
Now, these are my following tasks
1. Print a first column for every two rows that has the same value followed by a string.
2. Match on the... (3 Replies)
Hello experts,
Please help me in achieving this in an easier way possible. I have 2 csv files with following data:
File1
08/23/2012 12:35:47,JOB_5330
08/23/2012 12:35:47,JOB_5330
08/23/2012 12:36:09,JOB_5340
08/23/2012 12:36:14,JOB_5340
08/23/2012 12:36:22,JOB_5350
08/23/2012... (5 Replies)
I have two text files where the first three columns are exactly the same. I want to compare the fourth column of the text files and if the values are different, print that row into a new output file. How do I go about doing that?
File 1:
100 rs3794811 0.01 0.3434
100 rs8066551 0.01... (8 Replies)
Hi guys,
I'm rather new at using UNIX based systems, and when it comes to scripting etc I'm even newer.
I have two files which i need to compare.
file1: (some random ID's)
451245
451288
136588
784522
file2: (random ID's + e-mail assigned to ID)
123888 xc@xc.com
451245 ... (21 Replies)
Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2
file 1 sample
SNDK 80004C101 AT
XLNX 983919101 BB
NETL 64118B100 BS
AMD 007903107 CC
KLAC 482480100 DC
TER 880770102 KATS
ATHR 04743P108 KATS... (7 Replies)
ex:
a file has :
122323
123456456
125656879
678989965t635
234323432
b has :
this is finance no.
this is phone no
this is extn
ajkdgag
idjsidj
i want the o/p as:
122323 his is finance no.
123456456 this is phone no
123456456 ... (4 Replies)