Computing.Net > Forums > Solaris > Need to compare two files

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.

Need to compare two files

Reply to Message Icon

Name: kalyanbrata.dhar
Date: August 28, 2008 at 05:42:59 Pacific
OS: Sunos5.9
CPU/Ram: 10gb
Product: solaris
Comment:

Hi,
I have two files, file1 and file2. file2 is reference file and file1 is getting generated by sql script on fly. I need to check either all entries in file2 is present in file1 or not. If not, i need to print those entries from file2. common entries should not be there in the output file.
both the files are csv files.

file structures:

file1 looks like as below:


ORDER_IMPORT_HPIPE
ORDER_IMPORT_MHRWEB
SO_MODULE
MHE_PICKCNFM_INP
WORK_ORDER_RECPT_PROCESS
ORDER_IMPORT_ECOMMERCE

file2 looks like as below:

SO_MODULE
-
WORK_ORDER_ALLOC_PROCESS
SFA_ORDERS
CUSTOMER_IMPORT_PROCESS
WORK_ORDER_RECPT_PROCESS
ORDER_IMPORT_ECOMMERCE


output file should be

WORK_ORDER_ALLOC_PROCESS
SFA_ORDERS
CUSTOMER_IMPORT_PROCESS

kalyan



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 29, 2008 at 17:47:06 Pacific
Reply:

Brute force method. Let me know if you have any questions:


#!/bin/ksh

while read myline
do
cnt=0
while read line
do
if [[ "$myline" = "$line" ]]
then
((cnt+=1))
break
fi
done < file1
if [[ $cnt -eq 0 ]]
then
echo "$myline" >> output.file
fi
done < file2



0

Response Number 2
Name: kalyanbrata.dhar
Date: August 30, 2008 at 00:47:35 Pacific
Reply:

Thank you Nail for your help... It really worked..

kalyan


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Need to compare two files

how to show the file timestamp www.computing.net/answers/solaris/how-to-show-the-file-timestamp/5122.html

how to rm a file '-' www.computing.net/answers/solaris/how-to-rm-a-file-/3536.html

need to strip hex 92 characters www.computing.net/answers/solaris/need-to-strip-hex-92-characters/2875.html