I have two separate csv files(comma delimited) file 1 and file 2.
File 1 contains
File 2 contains
I need to join these two files based on the column name(i.e) using PAN,NAME etc..and if extra columns is available it needs to be created in the output file.
My output needs to be like this,
File 3
Please help me with the unix command..Thanks in advance
Last edited by Don Cragun; 07-25-2015 at 12:18 AM..
Reason: Add CODE tags, again.
If File 1 contained the additional line:
how would that be combined with the line:
from File 2?
Is there some field that will always be present in every input file?
Is there some field or combination of fields that is to be used a way to match lines from two files? Or, all all lines from all input files to be considered independent from all other input files and the only change in the output from the input lines is to add empty fields to lines from input files that don't have one or more of the headings from the combined list of input files?
Are you always processing two input files to produce one output file, or can there be more than two input files?
What determines the order of the fields in the output file? If you're processing File 1 and File 2 in that order, why couldn't the output field order be:
instead of:
and why did the heading you showed in File 3 change Dept (from File 2) to DEPT?
If one input file has the heading line: a,b,c,d and another input file has the heading line: D,C,A,B, are there supposed to be four fields in the output file or eight? (I.e., are heading labels case sensitive?)
I am using HP unix operating system..In my two csv files, the values exist in file 1 will not exist in file 2..Both are independent.
I want to merge these two files in a single file..but have to join between these files using column name.. I have to achieve like full outer join in rdbms.
But I have to achieve using shell scripts..
I need only the four fields in the output not eight fields and there are only two input files.
The output can be in any order even like this
Code:
PAN,NAME,DEPT,Salary..
If you require more inputs, please let me know.
Thanks in advance
Cute puzzle... Note that the output you said you wanted uses an output field separator of period (instead of comma) between the 1st two output fields for lines read from File 1. I assume that was unintentional and that you really wanted commas separating all output fields. To make processing easier, since you said that field headers are to be treated as case insensitive, the following code prints all output file headings using upper case letters.
Note that although this was tested with two input files, it will work with zero or more input files. And, to make your life easier, I strongly encourage you to avoid putting spaces in filenames.
You could try something like:
With your sample input files, it produces the output:
If you reverse the order of the input files you feed this program, you would get the output:
If someone else wants to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
The obvious guess would be that one or both of your input files is in DOS format (with <carriage-return><line-feed> line terminators) instead of UNIX format (with <newline> line terminators). To confirm, show us the output from the command:
I have three files with similar pattern i need to merge all the coloumns side by side from all three files according to the first coloumn example as shown below
I mentioned 5 coloumns only in example but i have around 15 coloumns in each file.
file1:
Name,Samples,Error,95RT,90RT... (4 Replies)
Example:
I have files in below format
file 1:
zxc,133,joe@example.com
cst,222,xyz@example1.com
File 2 Contains:
hxd
hcd
jws
zxc
cst
File 1 has 50000 lines and file 2 has around 30000 lines :
Expected Output has to be :
hxd
hcd
jws (5 Replies)
Hi all,
i need help.
I have two csv files with a huge amount of data.
I need the first column of the first file, to be compared with the data of the second, to have at the end a file with the data not present in the second file.
Example
File1: (only one column)
profile_id
57036226... (11 Replies)
I am trying to merge all csv files from source path into one single csv file in target. but getting error message:
hadoop fs -cat /user/hive/warehouse/stage.db/PK_CLOUD_CHARGE/TCH-charge_*.csv > /user/hive/warehouse/stage.db/PK_CLOUD_CHARGE/final/TCH_pb_charge.csv
getting error message:... (0 Replies)
I have lot of csv file collected from script like below :
Name of files (some examples) there are thousands of it:
192.168.0.123_251_18796_1433144473.csv
192.168.0.123_251_18796_1433144772.csv
192.168.0.123_251_18796_1433145073.csv
192.168.0.123_251_18796_1433145372.csvContent of each... (5 Replies)
Hi
I have multiple files each with two columns and I need to combine all those file into a tab delimited file. (multiple entry with same name separated by a comma)
The content of the files are as follows:
---
file1.txt:
name var1
aaa xx
aaa gg
bbb yy
ddd zz
---
file2.txt
... (8 Replies)
Hello everyone!!
I am not completely new to shell script but I havent been able to find the answer to my problem and I'm sure there are some smart brains here up for the challenge :D.
I have several CSV files that I need to combine into one, but I also need to know where each row came from.... (7 Replies)
Help in writing a script using sed which updates fileOne with the contents from fileTwo
Example:
Contents of fileOne
1,111111
2,897823
3,235473
4,222222
Contents of fileTwo
1,111111,A,1,2
4,222222,A,2,2
5,374632,A,3,2
6,374654,A,4,2
Final File should be:
1,111111,A,1,2... (9 Replies)
I have 2 files pipe delimted and want to merge them based on a key
e.g file 1
123$aaa$yyy$zzz
345$xab$yzy$zyz
456$sss$ttt$foo
799$aaa$ggg$dee
file 2
123$hhh
345$ddd
456$xxx
888$zzz
so if the key is the first field, and the result should be the common key between file 1 and 2 (6 Replies)