How to compare contents of two CSV rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare contents of two CSV rows
# 1  
Old 10-23-2008
How to compare contents of two CSV rows

I have been trying to find the answer to this but can't seem to get it.

I have two rows, both are CSV files.

I want to iteratively compare each field value to the corresponding value in the second file.

Example:
File 1.txt
1|hello|3.2|AMB||||B

File 2.txt
1|hi|3,2|ABC||||C

The result should spit out only the differences in 2.txt
Field $2: hi
Field $4: ABC

etc.

I have a feeling this is an AWK program but I'm new to it so if there is a one liner that can get me close then I would be interested. THanks in advance.
# 2  
Old 10-23-2008
How about first joining the file

join -t"|" 1.txt 2.txt|awk 'BEGIN{FS="|"} $2!=$9 {print 2,$9}'

Above does for field 2,Similarly need to do for other fields This is assuming 8 fields are there in the file.

Last edited by avis1981; 10-23-2008 at 07:56 PM.. Reason: Improving clarity
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

2. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

3. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

4. Shell Programming and Scripting

Compare contents of two files

Hello, I have two files containing both two columns: $ cat file1 col1 nbr1 col2 nbr2 col3 nbr3 ... $ cat file2 val1 ri1 val2 ri2 val3 ri3 ... I need to compare every nbr (nbr1, nbr2,...) in the second column of file1 with every ri (ri1, ri2,...) in the second column of... (5 Replies)
Discussion started by: newpromo
5 Replies

5. Shell Programming and Scripting

changing csv file contents to file of rows

i have a file a.txt contents as 1,2,3,4,......etc...in a single line, i want to write to another file in rows as 1 2 3 4 5 can u help? i do not know the length of a.txt (4 Replies)
Discussion started by: pravfraz
4 Replies

6. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

7. Shell Programming and Scripting

Compare folder contents over network

I use diff -r dir1 dir2 to get comparison of two folders that are on same machine. Now I need the same thing but one of the folders is on a different machine. Currently I ftp the folder to a temp folder compare using above command and delete the temp folder. Is there any other better options?... (5 Replies)
Discussion started by: ke3kelly
5 Replies

8. Shell Programming and Scripting

compare the contents of two directories

i have been asked to write a bash shell script comparing two directories and sed or awk should not be used in this assignment. compdir will compare filenames in two directories, and list information about filenames that are in one directory but not the other. The information listed will be a long... (1 Reply)
Discussion started by: soccerball
1 Replies

9. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies

10. UNIX for Dummies Questions & Answers

compare array contents with file

I have an array "arrA" with the following contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf My data file "Files.dat" has the same contents: A0012 Paint Shop.doc ES001 Contract Signature.doc Budget Plan.pdf TS PWS.pdf I have a script that compares... (0 Replies)
Discussion started by: orahi001
0 Replies
Login or Register to Ask a Question