Help with a script (tried but no luck)
Hi I have 2 files and i want to perform minus between file2 and file1
File2 has all Data and File1 has few data All i want is 2 things. 1. Generate the difference between file2 and file1 2. Generate "sing quotes" to column1 of file1 start and end either using awk/sed i Tried using while loop but no luck with the output. Both files has 2 columns your help is appreciated. file1 NAME State ------ ------ Casey MD David FL Edison NJ John CA Juliet CA Maddy VA file2 NAME State ------ ------ Austin AZ Bretea PA Casey MD David FL Edison NJ Jermey NC John CA Juliet CA Justin NC Maddy VA Michael FL Pascal CA Rick TX Robin NY Scott CA Slovas MD |
Do you have to know which file the unique lines belong to? If not, the following procedure should do the trick:
|
Thanks for your reply.
I just pulled the sample data. But my file has lines of 100 - 200 so File 1 has only few dataaset and file2 has more data so i want to pull whats not in file1 and print both columns Yes singlequote things is seperate ... assuming we get the difference from above as below John Casey then this is what i need 'John', 'Casey', |
Code:
grep -vFf file1 file2 | sed "s/\(^.*\) \(.*$\)/\'\1\' \'\2\'/" Quote:
|
Can some one please help me on the issue with difference like how to pull only things which are missing from file 1
Appreciate your help |
what about grep -vFf file1 file2 from post #4 ? have you tried it? What do you mean by 'Appreciate your help'
|
tried that no luck.
see below please $ cat f1 Casey MD David FL Edison NJ $ cat f2 Austin AZ Bretea PA Casey MD David FL Edison NJ Jermey NC John CA Juliet CA $ grep -vFf f1 f2 Austin AZ Bretea PA Casey MD David FL Edison NJ Jermey NC John CA Juliet CA the grep output should not print Casey/David/Edison, As said all i need is to print the data which is not in file1 |
it definitely works:
Code:
/tmp$ grep -vFf file1 file2 |
I just ran the exact same test, and got this result:
Code:
user@test01:~$ grep -vFf f1 f2 |
Here is what am using
Code:
$ uname -a |
try grep -vFxf file1 file2
|
The command you are all looking for is called "comm" which will list the records that are common, records that are in file 1 but file 2, records that are in file2 but not file 1.
For most things, the two files should be sorted first. |
So 'grep -vFf file1 file2' is working for me with grep 2.18 (latest stable) , for pan64 with grep 2.12 (24-Apr-2012), but not for maddyfreaks with the older grep 2.6.3 (02-Apr-2010).
It would have been nice if grep worked to avoid the sort before using comm. |
To my best knowledge the following command will print the data which is not present in file1.
diff file1 file2 | grep -i ">" | awk '{print $2"\t\t"$3}' Please reply if this helps you. Thanks, Kathirvel.S |
comm -1 -3 file1 file2
will do that. And without the reformatting and stripping processes. Sorting is only needed if the files are out of order. If they are out of order, than every method requires multiple passes to find out if something in one is not in the other (one pass through the second file for every record in the first). It is an N^2 problem... Which is why sorting is done first. |
All times are GMT -5. The time now is 07:09 PM. |