Computing.Net > Forums > Programming > Compare two files with an input fil

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Compare two files with an input fil

Reply to Message Icon

Name: jacky599
Date: October 8, 2008 at 08:42:53 Pacific
OS: Solaris
CPU/Ram: solaris
Product: sun
Comment:

I need to compare two files:
Basically I have an input file fileA.
which need to be compare with fileb located in /etc/lc/mbd directroy

Both file format is like:

abc01def:10.80.11.123

The input file format is:

abc01mns:10.80.11.1
dbc02mns:10.80.11.2
fbc01mns:10.80.11.3
rbc01mns:10.80.11.4
tbc01mps:10.80.11.5
abt05mns:10.80.11.6
zbc11mys:10.80.11.7
ttc01mns:10.80.11.8
hbc05mns:10.80.11.9
qbc01mns:10.80.11.10

So after comparison the script will say:
what has been dupicate and what not duplicate.

Thanks




Sponsored Link
Ads by Google

Response Number 1
Name: pball
Date: October 8, 2008 at 10:32:56 Pacific
Reply:

I made something but I'm not sure if it's what you want.

For example if your fileA has
A
B
C
F
Z

and the fileB has
A
B
F
y

the duplicates would be A, B, F
but for the differences do you want what is in fileA but not fileB or the other way? That bit of info would be of great help.
---------
EDIT

I think I have something for you
---------
@echo off
setlocal EnableDelayedExpansion

set f1=H:\test\fileA.txt
set f2=H:\test\fileB.txt
set dupout=H:\test\duplicate.txt
set uniout=H:\test\unique.txt

for /f "usebackq tokens=* %%a in ("%f1%") do (
set dif=2
for /f "usebackq tokens=* %%b in ("%f2%") do (
if %%a==%%b (
@echo %%a>>%dupout%
set dif=1
)
)
if !dif!==2 echo %%a >> %uniout%
)
echo unique to %f1% >> %uniout%
pause
---------

set f1 to the input file
set f2 to the file you wish to compare to
set dupout to the file where duplicate entries will be listed
set uniout to the file where entries unique to f1 will be listed

edited script to work with file paths that contain spaces, I love Judago for teaching me how to do that.


0

Response Number 2
Name: jacky599
Date: October 15, 2008 at 12:27:05 Pacific
Reply:

basically the output would tell me what not match between file1 and file2. As I mentioned earlier both file formats are same"

abc01mns:10.80.11.1
dbc02mns:10.80.11.2
fbc01mns:10.80.11.3


I tried the code you have sent me but NO LUCK.

$ ./Comp2FileA
./Comp2FileA: @echo: not found
./Comp2FileA[2]: setlocal: not found
./Comp2FileA[9]: syntax error at line 11 : `"usebackq tokens=* %%a in ("%f1%") do (
set dif=2
for /f "usebackq' unexpecte


0

Response Number 3
Name: pball
Date: October 15, 2008 at 13:05:36 Pacific
Reply:

I'm guessing from what you have there you didn't put the exact path of the file in the script.

Could you post what you have for the script, that would help greatly.


0

Response Number 4
Name: jacky599
Date: October 16, 2008 at 11:29:44 Pacific
Reply:

Here what I have :


@echo off
setlocal EnableDelayedExpansion

set f1=fileA
set f2= /export/hm/dbpd.db
set dupout=duplicate.txt
set uniout=unique.txt

for /f "usebackq tokens=* %%a in ("%f1%") do (
set dif=2
for /f "usebackq tokens=* %%b in ("%f2%") do (
if %%a==%%b (
@echo %%a>>%dupout%
set dif=1
)
)
if !dif!==2 echo %%a >> %uniout%
)
echo unique to %f1% >> %uniout%
pause


##############
output with error:

$ ./Comp2FileA
./Comp2FileA: @echo: not found
./Comp2FileA[2]: setlocal: not found
./Comp2FileA[9]: syntax error at line 11 : `"usebackq tokens=* %%a in ("%f1%") do (
set dif=2
for /f "usebackq' unexpected


0

Response Number 5
Name: pball
Date: October 16, 2008 at 14:27:15 Pacific
Reply:

well i solved the problem. Sorry I didn't see you are running Solaris. I wrote up a batch script for Windows.

I guess you'll have to wait till someone with Solaris know how comes along.

Sorry again


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Compare two files with an input fil

Compare files with AWK www.computing.net/answers/programming/compare-files-with-awk/15182.html

Comparing two files www.computing.net/answers/programming/comparing-two-files/13292.html

compare two file www.computing.net/answers/programming/compare-two-file/19932.html