find same values(duplicate) or vlookup formula
Moderator: DosItHelp
find same values(duplicate) or vlookup formula
hi,
i have two text files, i want to find common values in that(duplicate) like vlookup formula which we use in excel sheet.
example:-
sample1.txt contains
33
445
667
22
45
97
67
57
86
8585
789
sample2.txt
565
46534
656
87
35
33
86
output in sample3.txt:-
33
86
i have two text files, i want to find common values in that(duplicate) like vlookup formula which we use in excel sheet.
example:-
sample1.txt contains
33
445
667
22
45
97
67
57
86
8585
789
sample2.txt
565
46534
656
87
35
33
86
output in sample3.txt:-
33
86
Re: find same values(duplicate) or vlookup formula
Try this
Regards
aGerman
Code: Select all
>"sample3.txt" type nul
for /f "usebackq delims=" %%A in ("sample1.txt") do (
for /f "usebackq delims=" %%a in ("sample2.txt") do (
if "%%A"=="%%a" >>"sample3.txt" echo\%%A
)
)
Regards
aGerman
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: find same values(duplicate) or vlookup formula
download gawk for windows, then use this one liner
this has the advantage of using memory which is faster than double for loops from aGerman's solution.
Code: Select all
c:\test> gawk.exe "FNR==NR{a[$1];next}($1 in a)" file1 file2
33
86
this has the advantage of using memory which is faster than double for loops from aGerman's solution.
Re: find same values(duplicate) or vlookup formula
hi friends
thanks for both of u.it works good.
In my office pc i dont have authority to install any package,already i told this to agerman that dont use any vbsctipt r gawk.
Anyway ghostmachine, thanks for your idea i will use in my home pc.
thanks for both of u.it works good.
In my office pc i dont have authority to install any package,already i told this to agerman that dont use any vbsctipt r gawk.
Anyway ghostmachine, thanks for your idea i will use in my home pc.
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: find same values(duplicate) or vlookup formula
santhosh wrote:hi friends
thanks for both of u.it works good.
In my office pc i dont have authority to install any package,already i told this to agerman that dont use any vbsctipt r gawk.
you can download from your home, its just an exe file. Put it inside your portable disk or USB drive, then bring to workplace to use.
Re: find same values(duplicate) or vlookup formula
hi ghostmachine,
c:\test> gawk.exe "FNR==NR{a[$1];next}($1 in a)" file1 file2
now i want to print values which is not same.
c:\test> gawk.exe "FNR==NR{a[$1];next}($1 in a)" file1 file2
now i want to print values which is not same.
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: find same values(duplicate) or vlookup formula
santhosh wrote:hi ghostmachine,
c:\test> gawk.exe "FNR==NR{a[$1];next}($1 in a)" file1 file2
now i want to print values which is not same.
use a "!" to invert the condition
Code: Select all
gawk.exe "FNR==NR{a[$1];next}( !( $1 in a) )" file1 file2
Re: find same values(duplicate) or vlookup formula
Thanks ghostmachine.one more doubt.
want to compare only 2nd and 3rd column (both column should be equal)example:-
File1 contains:-
sat,005,87
sat1,09,95
sat3,40,98
sat4,50,99
sat5,40,97
File2 contains:-
ggg,010,55
hth,68,95
sat,42,97
sat6,40,98
output should be File3:-
sat,40,98
Thanks in advance
want to compare only 2nd and 3rd column (both column should be equal)example:-
File1 contains:-
sat,005,87
sat1,09,95
sat3,40,98
sat4,50,99
sat5,40,97
File2 contains:-
ggg,010,55
hth,68,95
sat,42,97
sat6,40,98
output should be File3:-
sat,40,98
Thanks in advance
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: find same values(duplicate) or vlookup formula
and how is that sat and not sat3 and sat6 ?
Re: find same values(duplicate) or vlookup formula
yes sorry ghost,
i missed that line
output is :-
sat3,40,98
sat6,40,98
i missed that line
output is :-
sat3,40,98
sat6,40,98