Join Two CSV Text Files

Write a shell script to join two CSV text files based on value of some columns?

Questions by bubgem27

Showing Answers 1 - 10 of 10 Answers

UncaAlby

  • Apr 20th, 2010
 

What exactly do you mean, "based on the value of some column" ?

Are you trying to get specific rows out of the file based on a column?  Is the criteria for getting rows different for the two files?

Let's make the following assumptions:

The criteria for the columns are the same.  The number of columns are the same.  This is your typical CSV file where the fields are separated by commas (,) and terminated by newlines.

The criteria we'll use for this example is that we want every row where column 7 is not equal to "NO".

cat file1 file2 [more files ...] | awk -F, '$7 != "NO" {print $0}' > resultfile

Now, if you want different criteria for different files, then you'll have to do something different.

oceanblue

  • May 15th, 2010
 

Join command can be used. To join on 1st field of each file
join -t, file1 file2

-t, is to indicate field separator is comma

To join on 3rd field of file1 and 4th of 2nd file
join -t, -13 -24 file1 file2

  Was this answer useful?  Yes

nkumar85

  • May 18th, 2010
 

Bash does not support this kind of feature, you can do this in PERL, because PERL supports all feature which are needed to work with CSV worksheets.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions