Hi Grial,
Thanks for your prompt and quick response.
The script works for comparing two cols i.e., col 3 and col4 of two files.
If i try to try to compare only col3 of two files,
I am getting redundant records.
Eg:
My File1 consists of 100 records and
file2 consists of 238 records.If i try to compare,file1 and file2 I got 116 records as my o/p
in the console.Can u suggest me,how to rectify this.
Again, I don't know if I've understood. Do you mean you could have duplicate records on file2? Or, Do you want only the first ocurrence? If this is teh case, try:
#!/bin/bash
comp1=($(cat text1.txt | cut -d\; -f 3,4))
comp2=($(cat text2.txt | cut -d\; -f 3,4))
for str in ${comp1[*]}; do
i=0
while (( $i < ${#comp2[*]} )); do
if [[ $str = ${comp2} ]]; then
cat text1.txt | grep $str
break
fi
(( i += 1 ))
done
done
Hi Grial,
Again thanx for ur kind repsonse,Let me explain clearly.
I have compared col3 of file1 and col3 of file2.
I got duplicates of file1 with the latest script send by you.
And one more thing is that,i will not be getting any duplicate records for both the files.
Just i want to check columns/column of file1 with file2.
OK.
col3-to-col3 always or col3-to-colX or colX-to-colY?
In your example you are comparing whole lines with whole lines...
mmmmm:
#!/bin/bash
> success.txt
> fail.txt
comp1=($(cat text1.txt))
comp2=($(cat text2.txt))
for str in ${comp1[*]}; do
i=0
FOUND=no
while (( $i < ${#comp2[*]} )); do
if [[ $str = ${comp2} ]]; then
cat text1.txt | grep $str >> success.txt
FOUND=yes
break
fi
(( i += 1 ))
done
if [[ $FOUND = no ]]; then
cat text1.txt | grep $str >> fail.txt
fi
done
As i have said its a one-one mapping,but the columns can be dynamic.
It can be col X(file1)-col 1(file2) ,colX,colY(file1)-col1col2(file2).Is it possible with the current script.