i need to compare three files in unix
a.txt b.txt c.txt
1 2 1
2 5 3
4 6 5
5 6
6
i need to insert a blank line in the file if i don't find a match
and put the items at the same column if found a match
The items in the files appear in sorted order
The output should be
a.txt b.txt c.txt
1 blank 1
2 2 blank
blank blank 3
4 blank blank
5 blank 5
6 6 6
What have you tried, please share, so that someone can guide you.
Rakesh i have three columns in a file where numbers come in sorted order
1 2 1
2 5 3
4 6 5
5 6
6
Now i want to compare first item, second item third item and so on in each column
if i get a match in all three i let all the items remain as it is
eg in above
6 6 6
if i don't get a match i let the minimum of this at the same place and shift the other(s) down.
eg in the first line
1 2 1
i need to get
1 blank 1
blank 2 blank
so the total output of the above input file should look like
1 blank 1
2 2 blank
blank blank 3
4 blank blank
5 5 blank
6 6 6
i have wriiten blank so that it appear formatted here
I understood your requirement already.
Have you tried some code yourself? If yes, please share.
---------- Post updated 06-19-09 at 11:42 AM ---------- Previous update was 06-18-09 at 05:17 PM ----------
To start with, you can use the below code for comparing two files and inserting blanks.
sdiff file1 file2 | awk '{
if ($1==">")
$1=" "
if ($2=="<")
$2=" "
print
}'
Thanks Rakesh i had tried some solutions but the script for it is turning out to be too long , also the diff ,sdiff, comm all work for two files very well but i am looking to compare three files, if i bring third file into comparison the output of sdiff turns out to be of no use
---------- Post updated at 04:57 AM ---------- Previous update was at 02:48 AM ----------
Rakesh i was able to think of a solution where in
cat a.txt b.txt c.txt > d.txt
sort d.txt | uniq > test
then run a for loop in test and check for the item in each of a.txt b.txt c.txt
if the item not present insert a blank in the file
Thanks for you response and inputs regarding the same.