Problems comparing files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems comparing files
# 1  
Old 11-14-2008
Error Problems comparing files

Hello guys,

I have another problem, let me try to explain, i have two files:
Code:
cat file1
2623559
2623562
2623565
2623568
2619503

cat file2
"53382743","6600000000000256053",30,2
"53382744","6600000000000256054",30,2
"53382745","6600000000000256055",30,2
"53382746","6600000000000256056",30,2
"53382747","6600000000000256057",30,2

I need to compare all the rows of file1 with a part of a row in file2, and if it match, write all the row of file2 into file3.

For example:

row of file1: 2623559
match with a row in file2:"53382743","6600000000000256053",30,2
so this row will be writed on file3: "53382743","6600000000000256053",30,2

Thanx for your help.Smilie
# 2  
Old 11-14-2008
Quote:
...
row of file1: 2623559
match with a row in file2:"53382743","6600000000000256053",30,2
so this row will be writed on file3: "53382743","6600000000000256053",30,2
I don't understand .... 2623559 != 000256053?
# 3  
Old 11-14-2008
Quote:
Originally Posted by radoulov
I don't understand .... 2623559 != 000256053?
Sorry, here the right example:

row of file1: 2623559
match with a row in file2:"53382743","6600000000002623559",30,2
so this row will be writed on file3: "53382743","6600000000002623559",30,2
# 4  
Old 11-14-2008
Use nawk or /usr/xpg4/bin/awk on Solaris.

Code:
awk -F'","*' 'NR == FNR { 
  _[$0] 
  next 
  }
{ 
  f = $2
  sub(/[^0]*0*/, "", f)
  if (f in _) print
    }' file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. Homework & Coursework Questions

Comparing Files

Hello all. Quick question. I have to compare these 2 files and display the lines of one file that match a column in another file. So I have 2 files both contain 3 fields. I want to compare the first field from the first file to the second file. If there is a match I want to display the... (5 Replies)
Discussion started by: Introuble99
5 Replies

3. Shell Programming and Scripting

Comparing files in a directory against an array of files

I hope I can explain this correctly. I am using Bash-4.2 for my shell. I have a group of file names held in an array. I want to compare the names in this array against the names of files currently present in a directory. If the file does not exist in the directory, that is not a problem.... (5 Replies)
Discussion started by: BudMan
5 Replies

4. Shell Programming and Scripting

Comparing two files

I am trying to do a comparison between two files, and trying to output the difference between the two files. Let's take FileA.txt and FileB.txt for example: FileA.txt -------- Just A Fool:Christina Aguilera feat. Blake Shelton:Lotus (Deluxe Edition) Figure 8:Ellie Goulding:Halcyon... (4 Replies)
Discussion started by: todaealas
4 Replies

5. UNIX for Advanced & Expert Users

How to find duplicates contents in a files by comparing other files?

Hi Guys , we have one directory ...in that directory all files will be set on each day.. files must have header ,contents ,footer.. i wants to compare the header,contents,footer ..if its same means display an error message as 'files contents same' (7 Replies)
Discussion started by: Venkatesh1
7 Replies

6. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

7. Shell Programming and Scripting

Comparing two files

Hi, any suggestions to make an script doing the next steps? 1.- compare two files. 2.- generate and exit file per every difference found. 3.- every exit file must be named with the difference found and its content must be "1". We are beginners in shell scripting and any help... (2 Replies)
Discussion started by: emilnet
2 Replies

8. Shell Programming and Scripting

Need help comparing two files and deleting some things in those files!

So I have two files: File1 pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2 pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2 ref4948 1.1 treehouse.txt 1.6 ref8573 1.5 ref3284 1.4 ref5838... (24 Replies)
Discussion started by: linuxkid
24 Replies

9. UNIX for Advanced & Expert Users

comparing shadow files with real files

Hi I need to compare shadow file sizes with their real file counterparts. If the shadow file size differs form the realfile size then it must send a mail. My problem is that our system has over 1600 shadowfiles in different directories, with different names. the only consistancy is the .sh file... (4 Replies)
Discussion started by: terrym
4 Replies

10. UNIX for Dummies Questions & Answers

comparing files

Hi, i have a long script saved in two different folders at a different date...these two savings are nearly identical but i would like to know what are the differences between them without having to print and compare them line by line. maybe there is a "compare file1 file2" command? thx (2 Replies)
Discussion started by: tomapam
2 Replies
Login or Register to Ask a Question