- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Uregent : Record Comparison Between 3 files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-30-2001 08:54 AM
тАО01-30-2001 08:54 AM
Uregent : Record Comparison Between 3 files
I need to compare 3 files in this manner.
First i will take file1 and compare each and every record of file1 in terms of field with other 2 files. Based on process rules, i should do some action.
My question is how i can do record comparison among files ? I am trying to do this with Shell Scripting, AWK.
Could some one tell me the how can i
achive it ?
Awaiting your early reply.
Thanks
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-30-2001 09:03 AM
тАО01-30-2001 09:03 AM
Re: Uregent : Record Comparison Between 3 files
Look at the comm command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-30-2001 09:04 AM
тАО01-30-2001 09:04 AM
Re: Uregent : Record Comparison Between 3 files
Take a look at the man pages for 'diff' and 'cmp'.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-30-2001 10:40 PM
тАО01-30-2001 10:40 PM
Re: Uregent : Record Comparison Between 3 files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2001 01:25 PM
тАО02-01-2001 01:25 PM
Re: Uregent : Record Comparison Between 3 files
Thank you all for your reply.
Even if i am using 'comm' or diff command i can compare only 2 files. In my case i have to compare the entire record field by field from the first file with the other two files (again record field by field).
Awaiting ur reply.
Thanks
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-01-2001 02:25 PM
тАО02-01-2001 02:25 PM
Re: Uregent : Record Comparison Between 3 files
in the korn shell do something like this:
#save your IFS variable
OLDIFS=$IFS
#set IFS to your field seperator
IFS="," # comma seperated fields,
# probably want to add your
# record seperator here too
# open file descriptor to the files to be compared
exec 3< file1
exec 4< file2
cat yourfile |
while read field
do
read -u3 field1
read -u4 field2
if [[ $field != field1 ]] ;then
if [[ $field != field2 ]] ;then
do_case1 #!!
else
do_case2 #!=
fi
else
if [[ $field != field2 ]] ;then
do_case3 #=!
else
do_case4 #==
fi
fi
done
IFS=$OLDIFS
of course this assumes same number of records in each file and the same number of fields in each record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2001 04:40 AM
тАО02-02-2001 04:40 AM
Re: Uregent : Record Comparison Between 3 files
To acomplish this task I often use join command.
i.e:
sort f1 > f1.o
sort f2 > f2.o
sort f3 > f3.o
join -a 1 -a 2 -e "MISSING" -o 1.1 1.2 ... 2.1 2.2 file1.o file2.o > j1
join -a 1 -a 2 -e "MISSING" -o 1.1 1.2 ... 2.1 2.2 j1 file3.o > j2
And now is very easy to process with awk.
See man paste and join.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-02-2001 05:33 AM
тАО02-02-2001 05:33 AM
Re: Uregent : Record Comparison Between 3 files
in Xemacs editor, have a look at :
Tools->Compare->Three files...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2001 06:54 AM
тАО02-05-2001 06:54 AM
Re: Uregent : Record Comparison Between 3 files
Thanks every one for your reply.
Larson, my input files have the different no. of records and have the same no. of fields.
The field separator is pipe symbol (|).
I tried with this script,
Korn Shell
==========
OLDIFS="$IFS"
IFS=|
echo "Enter the first file"
read file1
echo "enter the second file"
read file2
exec 3<$file1
exec 4<$file2
exec 5>match
exec 6>nomatch
while read -u3 lineA
do
read -u4 lineB
if [ "$lineA" = "$lineB" ]
then
print -u5 "$lineA"
else
print -u6 "$lineA; $lineB"
fi
done
IFS=$OLDIFS
This scripts compare the records one after another from both the files. But what i need is,
i have to take a record from the first file (say file1) and compare that record with each and every record of the second file (say file2)
until EOF of file2. Similarly till EOF of file1.
Could you pl. anyone tell me how can i write the script to do this ?
I have a requirement to compare not only at the record level but i need to compare at the field level.
Awaiting your reply.
Thanks
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2001 08:11 AM
тАО02-05-2001 08:11 AM
Re: Uregent : Record Comparison Between 3 files
#read each line of your file
while read -u3 line
do
#test line against these files
for i in file1 file2
do
#get each line that is different + the line number
grep -nvx "$line" file1 |
while read dfline
do
#get the line number that is different
numRec=$(print "$dfline" | cut -d: -f1)
dfline=$(print "$dfline" | cut -d: -f2-)
numFields=$(print "$dfline" | awk -F\| '{print NF;}')
(( x = 0 ))
while (( $x < $numFields ))
do
(( x = $x + 1 ))
field=$(print "$line" | cut -d: -f"$x")
field1=$(print "$dfline" | cut -d: -f"$x")
if [[ "$field" != "$field1" ]] ;then
print "$file1:$numRec:$x:$field:$field1"
fi
done
done
done
done